代码之家  ›  专栏  ›  技术社区  ›  Josh

Linq to NHibernate-比较2个列表

  •  3
  • Josh  · 技术社区  · 15 年前

    我有两张单子,我需要知道是否有匹配的。我试过用 request.Interests.Intersect(x.Post.Tags.Split(' ')).Count() > 0 但我得到了错误

    System.NotImplementedException:系统.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)
                                                                                               )
                                            )
    

    当generateintesexpression中有断点时,它不会暂停。我试着构建一个递归函数来动态构建表达式,但我不知道如何将LINQ表达式链接在一起。对于如何用动态LINQ实现这一点有什么想法吗?

    1 回复  |  直到 15 年前
        1
  •  1
  •   Josh    15 年前

    我必须将其更改为使用HQL并动态构建HQL查询。

    推荐文章