Query Exception in Hierarchical Entity Framework

c# entity-framework

Question

Every member in a certain firm has a parent member, and I'm trying to build up a hierarchical collection using Entity Framework. However, when I try to execute this, I receive 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.

Any theories as to why this is happening? If I remove the ParentMember assign, everything works.

        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

The error message provides you a hint, but I haven't tested it: you're not setting the same properties in the same sequence in both locations.

What happens if you attempt to set the outer Member(ID )'s property?

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