开发者

anonymous type and multiple properties

I have this error: An anonymous type cannot have multiple properties with the same name. Whether this can be resolved with alias ie, whether an alias exists in 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 DevicesEntit开发者_StackOverflow中文版ies.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
                           };


You need to provide alternative names for the duplicate properties. For example:

select new {
   // ... other properties here ...
   dt.Name,
   dt.ArticleNumber,
   dt.Type,
   LastStartDate = l.StartDate,
   l.LocationNameId,
   CurrentLocation = loc.Name
};


It's a confligt on "Name" You are mapping both dt.Name and loc.Name, both which the compiler tries to set to the "Name" property of the anon type.

change one of them to e.g. LoationName = loc.Name.

HTH

[edit] Way too late to hit submit :-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜