在c#中linq不等于

Hir*_*isi 0 c# linq

我在我的项目中使用Linq.

我想要来自viewTeachers的所有老师,其中Mailcode不等于20.

我的代码是

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);
                    }
Run Code Online (Sandbox Code Playgroud)

我已经写了

!v.MailCode.Equals(20)
Run Code Online (Sandbox Code Playgroud)

但不确定它是否正确.

谁能告诉我怎么能这样做?

Hab*_*bib 7

您可以简单地将您的条件写为:

v.MailCode != 20
Run Code Online (Sandbox Code Playgroud)

所以你的where子句应该是:

where v.FullName.StartsWith(prefix) && v.MailCode != 20
Run Code Online (Sandbox Code Playgroud)