LINQ字符串数组不在

scr*_*r78 0 c# linq

使用LINQ如何让这个查询返回除字符串数组中的所有状态?

string[] states = { "FL", "CA", "IN", "AL", "MI" };
var headers = (from h in db.Headers
               where h.State != states.Any()
               select new
               {
                   description = h.Description,
                   state = h.State
               });
Run Code Online (Sandbox Code Playgroud)

Chr*_*tos 5

你可以试试这个:

 var headers = (from h in db.Headers
                where !states.Contains(h.State)
                select new
                {
                    description = h.Description,
                    state = h.State
                });
Run Code Online (Sandbox Code Playgroud)