我如何创建得到的一切,但一个特定的值LINQ查询 [英] How do I create a linq query that gets everything but a specific value
本文介绍了我如何创建得到的一切,但一个特定的值LINQ查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
说我有一个LINQ查询选择的R db.Roles那里r.RoleName不包含(管理员)选择 - [R;
这是不包含一部分有我的困惑。我知道我能做到这一点。载电话,但你怎么做相反的?
谢谢!
更新: 我发现排除法和这里是我如何使用它:
VAR作用=(来自R在db.Roles
排序依据r.RoleName
选择R)
。除(来自R在db.Roles
其中,r.RoleName ==管理员和放大器; r.RoleName ==DataEntry
选择ř
);
解决方案
请尝试以下
VAR的查询= db.Roles.Where(X =>!x.RoleName.Contains(管理员));
您可以只使用C#不是运营商! (惊叹号)。扩展LINQ语法版本
VAR的查询=
从它db.Roles
在那里!it.RoleName.Contains(管理员)
选择它;
Say I have a linq query select r in db.Roles where r.RoleName DOES NOT contain ("Administrator") select r;
It is the does not contain part that has me confused. I realize I can do that .Contains call but how do you do the opposite?
Thanks!
Update: I found the Exclude method and here is how I used it:
var role = (from r in db.Roles
orderby r.RoleName
select r)
.Except(from r in db.Roles
where r.RoleName == "Administrator" & r.RoleName == "DataEntry"
select r
);
解决方案
Try the following
var query = db.Roles.Where(x => !x.RoleName.Contains("Administrator"));
You can just use the C# not operator ! (exclamation point). Expanded LINQ syntax version
var query =
from it in db.Roles
where !it.RoleName.Contains("Administrator")
select it;
这篇关于我如何创建得到的一切,但一个特定的值LINQ查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文