Query Exception in Hierarchical Entity Framework

c# entity-framework

Question

I am attempting to build up a hierarchical collection using Entity Framework - see the below query - every member in a given company has a parent member - but when trying to execute this I get the following exception:

System.NotSupportedException: The type 'Member' appears in two structurally incompatible initializations within a single LINQ to Entities query. A type can be initialized in two places in the same query, but only if the same properties are set in both places and those properties are set in the same order.

If I remove the ParentMember assign it works - any ideas on what is going on?

        return from c in _Entities.Company
               where c.Deleted == false
                select new Member()
                {
                    Name = c.Name,
                    ParentMember = new Member() 
                    {
                        Name = c.ParentMember.Name
                    }
                }; 
1
10
11/9/2010 4:35:58 PM

Popular Answer

I haven't tried this, but the error message gives you a clue: you're not setting the same properties in the same order in both places.

What happens if you try setting an ID property on the outer Member()?

12
11/9/2010 4:00:45 PM


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