有主要查询
选择项目FROM QuickRecords WHERE(CategoryId = @CategoryId AND CategoryUserId = @UserId)
var q = from items in db.QuickRecords
where items.CategoryId == category && items.CategoryUserId == UserId
select items;
有动态过滤器,样本“22,333”
string[] filters = filter.Split(',');
foreach (string item in filters)
{
string f = "%" + item.ToLower() + "%";
q = q.Where(x => x.Record.Contains(f));
}
如何添加到SQL查询
AND(记录喜欢'%22%'或记录喜欢'%333%')
答案 0 :(得分:2)
string[] filters = filter.Split(',');
var q = from items in db.QuickRecords
where items.CategoryId == category && items.CategoryUserId == UserId
&& filters.Any(f=> item.Record.Contains(f))
select items;