小编Sud*_*002的帖子

为什么我没有收到Null引用异常?

我正在使用LINQ to Entities从数据库中获取一些数据。以下是我的查询。

var location = from l in dbContext.Locations
join e in dbContext.Equipment on l.ID equals e.LocationID into rs1
from e in rs1.DefaultIfEmpty()
where ids.Contains(l.ID)
select new
{
    EquipmentClass = e,
    LocationID = l.ID,
    LocationName = l.Name,
    EquipmentName = e == null ? null : e.Name,
    Description = e == null ? null : e.Description,
    InServiceStatus = e == null ? false : e.InServiceStatus,
    EquipmentType = e.EquipmentType.Name
};

foreach (var item in location)
{
    // some logic
}
Run Code Online (Sandbox Code Playgroud)

在上面的代码中, …

c# linq linq-to-entities

3
推荐指数
1
解决办法
316
查看次数

标签 统计

c# ×1

linq ×1

linq-to-entities ×1