1
votes

Are the classes generated by DbContext Generator in EF4.1 considered as POCO and persistence ignorant?

If so, why am I getting an error: "The entity or complex type '' cannot be constructed in a LINQ to Entities query."?

This is my code:

return searchParam = from p in ent.PartnerProfiles
                  select new PartnerProfile
                  { 
                      PartnerName =  p.PartnerName
                  }.ToList();
1

1 Answers

0
votes

Yes you can consider them to be POCOs and persistence ignorant, because they haven't got the wiring for notifying and tracking changes that the classes from an ObjectContext generator have.

That said, there are some conditions that EF requires for lazy loading to be enabled (virtual navigation properties) and in really persistent ignorant classes you won't find primitive primary or foreign key properties. The latter are not required, but very convenient at times (see foreign key associations).

The error you get is by design. The reason for it is not well documented (as far as I know) but it probably has to do with the fact that EF only wants to track entities it has created itself, not the ones you generate in a projection. For many EF users this difference would not be obvious. I described some more detail here.