Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All,

can anybody help me to resolve this.
the entity or complex type cannot be constructed in a linq to entities query.

The entity or complex type 'testModel.member' cannot be constructed in a LINQ to Entities query.

Thanks a lot...
Posted
Comments
Prasad Avunoori 2-Jun-14 3:10am    
Please share the code where got the error?
DaveAuld 2-Jun-14 3:25am    
Please post the code for the model.
[no name] 16-Sep-14 1:59am    
Please post your block of code for LINQ so that we could get to know the Issue.
Thanks

use AsEnumerable with the entity like this!

public IEnumerable<dml.person> GetAll()
        {
       
            var a = (from p in dbo.Person.AsEnumerable()
                     join r in dbo.Role.AsEnumerable() on p.PersonRoleID equals r.RoleID
                     select new DML.Person { 
                      Name =  p.Name,
                       Role= r.Name

                     });

           return a;

        }
</dml.person>
 
Share this answer
 
v2
Comments
kirbinator 22-Mar-16 23:24pm    
Adding AsEnumerable was easy and worked perfectly. Thanks.
If you search google there is a whole host of examples of this question being asked.

There is even one on here: Error "The entity or complex type 'EPatient.Models.cls_Measurement' cannot be constructed in a LINQ to Entities query."[^]

Maybe you have the same problem and the solution equally applies to you.

Given the limited information we can see, and having no access to your solution, that is the best I can suggest.
 
Share this answer
 
v2
Comments
Member 13337154 30-Aug-17 5:16am    
It is perfectly working.Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900