dinotom
dinotom

Reputation: 5162

getting values from a table where value is not null

When doing an EF query in the code behind using LINQ, how does one go about retrieving only those items in a nullable column that actually have data?

for example;

Dim unit = (From d in ctx.Inventories
           Where d.ProductId Is Not Null
           Select d).ToList()

Where obviously that query doesnt work, how does one go about this?

Upvotes: 0

Views: 37

Answers (1)

Reed Copsey
Reed Copsey

Reputation: 564333

Since ProductId is likely a nullable type, you should be able to do:

Dim unit = (From d in ctx.Inventories
       Where d.ProductId.HasValue
       Select d).ToList()

Upvotes: 2

Related Questions