Reputation: 1177
using LINQ how do I get this query to return all states except for the ones in the string array?
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
});
Upvotes: 0
Views: 295
Reputation: 101742
Probably you should use Contains
because it will be translated as NOT IN
into SQL
however this is how you can do it with Any
, it should be translated as NOT EXISTS
:
var headers = (from h in db.Headers
where !states.Any(x => x == h.State)
select new
{
description = h.Description,
state = h.State
});
Upvotes: 1
Reputation: 53958
You could try this:
var headers = (from h in db.Headers
where !states.Contains(h.State)
select new
{
description = h.Description,
state = h.State
});
Upvotes: 5