views:

80

answers:

1

Hi folks,

can someone please confirm/correct me, with my understanding of using POCO's with the Entity Framework v4?

If I'm going to want to use POCO's with my EF4 context, do I still need to place/create ENTITIES on the designer/.edmx ? Isn't the idea of using POCO's so I don't need to use those 'heavy' entities? or do i still need those entities, it's just that somewhere else I actually move the data out of the entities and into my POCO's .. which is what gets used by any consuming code?

+1  A: 

If you want to use POCO you have three choices:

First choice is to create EDMX model. In EDMX you will turn off code generation so the model will not create heavy entities for you. Than you will create your POCO classes which have to follow these constraints:

  • Each class has to have same name as entity in the model
  • Each class has to have parameterless constructor. Should be public but I think it also works with protected.
  • Each class has to have all properties (inclucing navigation properties) with exactly same names as in the model. All properties except navigation collections has to have getter and setter (at least protected).
  • Properties for navigation collections have to be at least type of ICollection<T> and you have to initialize them (that is the reason why they don't need setter). This is not the case for tracking proxies where EF initializes the collection.

Second choice is same as first but you don't create POCO classes by yourselves. Instead you use POCO template which can be downloaded to VS 2010. This template uses .tt file to generate POCOs for you.

Third choice is to use Code First approach where you code your POCOs and you define mapping in code. To do this you need EF 4.0 Feature CTP. I thik this is the only way how to use POCOs without EDMX model. But it is only CTP with many limitations at the moment.

Ladislav Mrnka
Danke. I was afraid I still had to make those bloody entities still :(
Pure.Krome