Linq to Nhibernate - Compare 2 lists
I have 2 lists and I need to know if there are any matches. I've tried using request.Interests.Intersect(x.Post.Tags.Split(' ')).Count() > 0
but I get the error
System.NotImplementedException : The method Intersect is not implemented.
So, I tried a recursive function that returns a bool. And it's as if the function call is just ignored.
Here's my function
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;
}
here's what the relevant piece of my linq expression looks like.
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)
)
)
When GenerateInteresExpression has a breakpoint in it, it does not pause. I tried building a recursive function to build the expression on the fly, but I can't figure out how to chain the linq expressions together. Any ideas on how to accomplish this with dynamic linq for linq to nhibernate开发者_运维技巧?
I had to change it to use HQL and dynamically build the HQL query.
精彩评论