var devSum = repository.Devices
.Where(dev => dev.Id == deviceId)
.Join(repository.ManagementGroups, device => device.ManagementGroupId, mGroup => mGroup.Id, (device, mGroup) => new { device, mGroup.Name })
.Join(repository.DataGroups, device_mGroup => device_mGroup.device.DataGroupId, dGroup => dGroup.Id, (device_mGroup, dGroup) => new { device_mGroup.device, managerName = device_mGroup.Name, dataName = dGroup.Name })
.Join(repository.DeviceTypes, d => d.device.TypeId, t => t.Id, (d, t) => new { d.device, d.dataName, d.managerName, TypeName = t.Name })
.SingleOrDefault();
嗨,我有上面的查询加入了几个表,一切正常。然后我意识到一些外键可能是空的。
我研究了GroupBy
and的用法DefaultIfEmpty
,它们听起来很有希望,所以我尝试将第一个更改Join
为GroupJoin
on 但这引发了错误:
var devSum = repository.Devices
.Where(dev => dev.Id == deviceId)
.GroupJoin(repository.ManagementGroups, device => device.ManagementGroupId, mGroup => mGroup.Id, (device, mGroup) => new { device, mGroup.Name })
.Join(repository.DataGroups, device_mGroup => device_mGroup.device.DataGroupId, dGroup => dGroup.Id, (device_mGroup, dGroup) => new { device_mGroup.device, managerName = device_mGroup.Name, dataName = dGroup.Name })
.Join(repository.DeviceTypes, d => d.device.TypeId, t => t.Id, (d, t) => new { d.device, d.dataName, d.managerName, TypeName = t.Name })
.SingleOrDefault();
'AnonymousType#1' does not contain a definition for 'Name' and no extension method 'Name' accepting a first argument of type 'AnonymousType#1' could be found (are you missing a using directive or an assembly reference?)
有人可以帮忙吗?