0

在使用 LINQ 的代码中执行 EF 查询时,如何仅检索可空列中实际包含数据的那些项目?

例如;

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

显然该查询不起作用的地方,如何解决这个问题?

4

1 回答 1

2

由于ProductId可能是可为空的类型,因此您应该能够:

Dim unit = (From d in ctx.Inventories
       Where d.ProductId.HasValue
       Select d).ToList()
于 2013-08-22T17:50:31.873 回答