Linq 匿名类型和多个属性
我有一个错误:匿名类型不能有多个同名属性。是否可以使用别名ie解决此问题,LINQ中是否存在别名Linq 匿名类型和多个属性,linq,Linq,我有一个错误:匿名类型不能有多个同名属性。是否可以使用别名ie解决此问题,LINQ中是否存在别名 var device_query = from d in DevicesEntities.device join dt in DevicesEntities.devicetype on d.DeviceTypeId equals dt.Id join l in DevicesEntities.location on d.Id equals l.De
var device_query = from d in DevicesEntities.device
join dt in DevicesEntities.devicetype on d.DeviceTypeId equals dt.Id
join l in DevicesEntities.location on d.Id equals l.DeviceId
join loc in DevicesEntities.locationname on l.LocationNameId equals loc.Id
where l.DeviceId == d.Id
select new {
d.Id,
d.DeviceTypeId,
d.SerialNumber,
d.FirmwareRev,
d.ProductionDate,
d.ReparationDate,
d.DateOfLastCalibration,
d.DateOfLastCalibrationCheck,
d.CalCertificateFile,
d.Notes,
d.TestReportFile,
d.WarrantyFile,
d.CertificateOfOriginFile,
d.QCPermissionFile,
d.Reserved,
d.ReservedFor,
d.Weight,
d.Price,
d.SoftwareVersion,
dt.Name,
dt.ArticleNumber,
dt.Type,
l.StartDate, //AS LastStartDate,
l.LocationNameId,
loc.Name //in this line I have problem
};
您需要为重复的属性提供替代名称。例如:
select new {
// ... other properties here ...
dt.Name,
dt.ArticleNumber,
dt.Type,
LastStartDate = l.StartDate,
l.LocationNameId,
CurrentLocation = loc.Name
};
这是“名字”的冲突
您正在映射dt.Name和loc.Name,编译器试图将两者设置为anon类型的“Name”属性
将其中一个更改为,例如LoationName=loc.Name
嗯
[编辑]
太晚了,无法点击提交:-)@ognjenb-我不知道你在问什么。确实,匿名类型不能有多个同名属性。但是如何创建这种类型的实例呢?您是否询问LINQ是否会自动创建别名?如果您有一些示例代码,它会有所帮助。谢谢