An anonymous type cannot have multiple properties with the same name [Resolved]

Posted by Kasani007 under C# on 11/16/2015 | Points: 10 | Views : 957 | Status : [Member] | Replies : 3
var Details = (from conAd in contactInformation.TransportAddresses
where conAd.AddressInformation.AddressId == 2
select new
{

conAd.AddressInformation.StateInformation.CountryInformation.LongName,
conAd.AddressInformation.StateInformation.LongName,


}).ToList();


It Is Showing Error "An anonymous type cannot have multiple properties with the same name",

how can I change the name "LongName" as it is from existing object

please help me




Responses

Posted by: Rajnilari2015 on: 11/17/2015 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
The issue is in the anonymous type

select new
{
conAd.AddressInformation.StateInformation.CountryInformation.LongName,
conAd.AddressInformation.StateInformation.LongName
}


The same name has been used twice.

Please provide explicit property name to resolve this like

select new
{
CountryLongName = conAd.AddressInformation.StateInformation.CountryInformation.LongName,
StateLongName = conAd.AddressInformation.StateInformation.LongName
}


hope this helps.

--
Thanks & Regards,
RNA Team

Kasani007, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kasani007 on: 11/17/2015 [Member] Starter | Points: 25

Up
0
Down
hi Rajnilari,

how can i give CountryLongName and StateLongName ,
where i have to define them...

please clarify my doubt

Kasani007, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajnilari2015 on: 11/17/2015 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 25

Up
0
Down
Inside the anonymous types

select new
{
//here you need to place CountryLongName and StateLongName as shown above e.g.

CountryLongName = ..... ,

StateLongName = .........


}


--
Thanks & Regards,
RNA Team

Kasani007, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response