Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework & Self-Tracking Entities vs POCO

If i'm wanting to use entity framework 4 as my data layer and want to send my entities to another tier whether it be via WCF or another mechanism and then want the ability to update the entities and send them back for updating/deleting/inserting is it best to use self-tracking entities or poco objects?

I'd rather use POCO objects if possible because i don't want to depend on the entity framework in the other layers if possible but i don't know how difficult it is to reconnect POCOs to the context.

like image 997
coding4fun Avatar asked Feb 24 '23 02:02

coding4fun


1 Answers

This is combination of too many questions and most of them were already asked on SO:

  • What is a purpose of Self tracking entities
  • Self tracking entities vs. POCO entities
  • How would I know if I should use Self-Tracking Entities or DTOs/POCOs

Using STEs will not make your upper layer dependent on EF but as described in second link STEs are not solution for every application. STEs have some other limitations, for example even on server side you cannot use lazy loading, you cannot apply changes when entity in the same key already exists in the context, etc.

Using POCOs and WCF means that you will work with detached entities and you will have to say EF what has changed. This can be simple in case of updating single entity and it is also possible to update only some fields from single entity but this can be very complex when updating the entity graph especially when you can delete relations on the client (in such case the easiest way is to load the entity graph first and merge incoming changes to attached entities).

like image 120
Ladislav Mrnka Avatar answered Mar 31 '23 15:03

Ladislav Mrnka