Error multiple properties with the same name in LINQ query

c# entity-framework-6 linq linqpad

Question

I am working on Linq query and I am getting error on functionNavigation_b.Title column. I am using LinqPad to test my queries initially,

Error

An anonymous type cannot have multiple properties with the same name

enter image description here

LINQ Query

from functionNavigation in Sys_Nav_Functions
join functionHierarchy in Sys_Nav_FunctionHierarchies on functionNavigation.Function_ID equals functionHierarchy.Function_ID 
join functionNavigation_b in Sys_Nav_Functions on functionHierarchy.Parent_Function_ID equals functionNavigation_b.Function_ID
 select new {
              functionNavigation.Function_ID, 
              functionNavigation.Title, 
              functionNavigation.Hierarchy_Level,
              functionHierarchy.Parent_Function_ID, 
              functionNavigation_b.Title 
            }
1
-3
6/24/2016 9:06:19 AM

Accepted Answer

An anonymous object can't have two properties with the same name.

Change your anonymous projection, give a different name to the second Title property.

functionNavigation.Function_ID, 
functionNavigation.Title, 
functionNavigation.Hierarchy_Level,
functionHierarchy.Parent_Function_ID, 
TitleB= functionNavigation_b.Title //or ParentTitle, or whatever you want
4
6/24/2016 9:09:41 AM

Popular Answer

Error is clear, you have duplicate Title name.

Try specifying unique name.

functionNavigation.Function_ID, 
functionNavigation.Title, 
functionNavigation.Hierarchy_Level,
functionHierarchy.Parent_Function_ID, 
AnotherTitle= functionNavigation_b.Title 


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow