匿名类型和多个属性

Ogn*_*jen 16 linq

我有这个错误:匿名类型不能有多个具有相同名称的属性.是否可以使用别名解析,即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.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
                           };
Run Code Online (Sandbox Code Playgroud)

Jon*_*eet 47

您需要为重复的属性提供替代名称.例如:

select new {
   // ... other properties here ...
   dt.Name,
   dt.ArticleNumber,
   dt.Type,
   LastStartDate = l.StartDate,
   l.LocationNameId,
   CurrentLocation = loc.Name
};
Run Code Online (Sandbox Code Playgroud)