Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deal with duplicate anonymous type member conflicts?

I am creating an anonymous type and I have conflicting field names.

The following code is failing because i.Name and i.Target.Name both have a property with the same name; "Name".

How do I get around this ? Here is the code:

i => new
{
    i.Name,
    i.Target.Name,
    i.EndDate,
    i.LastUpdated
};
like image 573
leora Avatar asked Jun 02 '10 21:06

leora


2 Answers

Name the anonymous fields, as such:

new {Name = i.Name, targetName = i.Target.Name, ... };
like image 170
Donnie Avatar answered Oct 25 '22 04:10

Donnie


 i => new
      {
          i.Name,
          TargetName = i.Target.Name,
          i.EndDate,
          i.LastUpdated
        });
like image 43
bkaid Avatar answered Oct 25 '22 06:10

bkaid