I have 2 lists and I need to know if there are any matches. I tried to use request.Interests.Intersect(x.Post.Tags.Split(' ')).Count() > 0, but I get an error
System.NotImplementedException: Intersect method is not implemented.
So, I tried a recursive function that returns bool. And as if the function call was simply ignored.
Here is 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;
}
this is what the corresponding part 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 a GenerateInteresExpression has a breakpoint in it, it does not pause. I tried to build a recursive function to create an expression on the fly, but I cannot figure out how to group linq expressions together. Any ideas on how to do this with dynamic linq for linq for nhibernate?