var devSum = repository.Devices
.Where(dev => dev.Id == deviceId)
.SingleOrDefault();
vmDeviceSummary result = new vmDeviceSummary
{
DeviceId = deviceId,
DeviceName = devSum.Name,
MacAddress = devSum.MacAddress,
DeviceType = devSum.DeviceType.Name,
Enabled = devSum.Enabled.ToString(),
ConfigurationLoaded = devSum.ConfigurationLoaded.ToString(),
AllowReload = devSum.AllowDataReload.ToString(),
DataGroup = devSum.DataGroup.Name,
ManagementGroup = devSum.ManagementGroup.Name,
};
我认为这应该可以工作,但是如果指向 datagoups 或 managementGroup 实体的链接中的外键中有空值,则会引发错误。
我该如何解决这个问题,使它像一个外部连接并返回 null?