开发者

ENTITY FRAMEWORK Error in LINQ Query "An anonymous type cannot have multiple properties with the same name"

开发者 https://www.devze.com 2023-02-10 19:33 出处:网络
I have a table \'Interval\' that contain multiple foreign key from \"DutationType\" Table I have a written a LINQ query like this

I have a table 'Interval' that contain multiple foreign key from "DutationType" Table I have a written a LINQ query like this

var listIntervalDurationType = 
   (from I in oSanEntities.Intervals 
       select new { I.IntervalId, I.IntervalName, I.IntevalTime, 
                    I.DurationType开发者_如何学Go1.TypeName, I.DurationType.TypeName, 
                    I.RetainTime });

But this give the error

An anonymous type cannot have multiple properties with the same name" because of anonymous types are not allow multiple property with same name

For resolve this error I added new property in DutationType entity but there is a mapping error occuring.

What is the solution for that?


Try this:

var listIntervalDurationType = (from I in oSanEntities.Intervals select new {   
I.IntervalId, 
I.IntervalName, 
I.IntevalTime, 
Duration1TypeName = I.DurationType1.TypeName,  
DurationTypeName = I.DurationType.TypeName, 
I.RetainTime });

As message said, you can't have two properties with name TypeName. You should also name Duration1 correctly in database diagram.

0

精彩评论

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