3

2 つのリストがあり、一致するものがあるかどうかを知る必要があります。使用してみましrequest.Interests.Intersect(x.Post.Tags.Split(' ')).Count() > 0たが、エラーが発生します

System.NotImplementedException : メソッド Intersect が実装されていません。

そこで、bool を返す再帰関数を試してみました。そして、関数呼び出しが単に無視されているかのようです。

これが私の機能です

private bool GenerateInterestsExpression(string postTags, string[] interests)
        {
            if (interests.Length == 0)
                return false;

            string interest = interests[0];

            var newInterests = interests.ToList();
            newInterests.Remove(interest);

            return GenerateInterestsExpression(postTags, newInterests.ToArray()) || postTags.ToLowerInvariant().IndexOf(interest.ToLowerInvariant()) >= 0;
        }

私のlinq式の関連部分は次のようになります。

request.Profile.Tags.Count == request.Interests.Length

                                        ||

                                        (
                                            request.Profile.Tags.Count != request.Interests.Length

                                            &&

                                            x.Post.Tags != String.Empty

                                            &&

                                            (
                                                GenerateInterestsExpression(x.Post.Tags, request.Interests)
                                                                                           )
                                        )

GenerateInteresExpression にブレークポイントがある場合、一時停止しません。その場で式を構築するために再帰関数を構築しようとしましたが、linq 式を連鎖させる方法がわかりません。linq to nhibernate の動的 linq でこれを達成する方法についてのアイデアはありますか?

4

1 に答える 1

1

HQLを使用し、HQLクエリを動的に構築するように変更する必要がありました。

于 2010-08-13T16:05:07.037 に答える