我想用不同的键搜索我的数据库。根据输入,可能有1键到10键。有没有一种方法可以动态地向我的Linq查询添加OR/AND子句?
keys[k] // I have my keys in this array
var feedList = (from feed in ctx.Feed
where feed.content.contains(keys[0])
&& feed.content.contains(keys[1])
&& ... // continues with the keys.length
select new {
FeedId = feed.DuyuruId,
FeedTitle = feed.FeedTitle,
FeedContent = feed.FeedContents,
FeedAuthor = user.UserName + " " +User.UserSurname
}
最佳答案
您可以尝试使用 .All
子句来检查所有键:
where keys.All(key => feed.content.contains(key))
关于c# - LINQ是否可以动态添加where子句,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14320049/