问题
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.
回答1:
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).
来源:https://stackoverflow.com/questions/6116002/entity-framework-self-tracking-entities-vs-poco