user1108948
user1108948

Reputation:

Is not null in EntityFramework query

Entity Framework 4.0 code first, C# 4.0. What is wrong for is not null in the code?

var query = from c in dbContext.table 
where c.FacilityID == facilityID && c.FilePath is Not null select c;

EDIT:

Many errors after adding is not null.

One of them is :

The type or namespace name 'Not' could not be found (are you missing a using directive or an assembly reference?)

Upvotes: 7

Views: 20387

Answers (1)

Jehof
Jehof

Reputation: 35544

Not is not a keyword in LINQ queries, so you will get the compiler errors. You need to use the inequality operator (!=) to check if FilePath is not null.

The code below should work for you

var query = from c in dbContext.table 
where c.FacilityID == facilityID && c.FilePath != null select c;

Upvotes: 12

Related Questions