[英]Is Not Equal in linq in c#
我在我的项目中使用Linq。
我希望所有Mailcode不等于20的viewTeachers的老师
我的代码是
var startWithFullName = from v in Db.viewTeachers
where v.FullName.StartsWith(prefix) && !v.MailCode.Equals(20)
orderby v.FullName
select new { v.ID, v.FullName };
foreach (var teacher in startWithFullName)
{
teacherTable.Rows.Add(teacher.FullName, teacher.ID);
}
我已经写了
!v.MailCode.Equals(20)
但不确定其正确与否。
谁能告诉我该怎么做?
您可以简单地将条件写为:
v.MailCode != 20
因此,您的where子句应为:
where v.FullName.StartsWith(prefix) && v.MailCode != 20
该条件可以写成!= 20
..
像这样的东西:
var startWithFullName = from v in Db.viewTeachers
where v.FullName.StartsWith(prefix) && v.MailCode != 20
orderby v.FullName
select new
{
v.ID,
v.FullName
};
它不会编译。 等于在联接和条件中使用!=。 希望这能消除您的疑虑。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.