如何在一列中搜索具有许多参数的LINQ? [英] How search LINQ with many parametrs in one column?
本文介绍了如何在一列中搜索具有许多参数的LINQ?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如,具有此表:
Name | BodyType
----------------
John | 1
Ted | 2
Daniel| 3
George| 4
我的应用程序我选中"1","2"和"3"复选框.我应该找到3行(John,Ted,Daniel),而不是George.如何在LINQ中获得此查询? (不使用where p.BodyType!=4
)
使用逻辑 OR
I my app i check "1" "2" and "3" checkbox. And i should find 3 rows (John, Ted, Daniel) and NOT George. How can i get this query in LINQ? (not use where p.BodyType!=4
)
Use logic OR
var all = dataContext.Users;
foreach (searchParameter in search)
...?
推荐答案
将所需的ID放入List<int>
,然后放入Contains
:
Put the required IDs into a List<int>
and then Contains
:
var bodyTypes = GetBodyTypesFromSearchParameters();
var query = dataContext.Users.Where(user => bodyTypes.Contains(user.BodyType));
这篇关于如何在一列中搜索具有许多参数的LINQ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文