我有 2 个列表,我需要知道是否有任何匹配项。我试过使用request.Interests.Intersect(x.Post.Tags.Split(' ')).Count() > 0
,但我得到了错误
System.NotImplementedException :方法 Intersect 未实现。
所以,我尝试了一个返回布尔值的递归函数。就好像函数调用被忽略了。
这是我的功能
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 为 linq 休眠的任何想法?