实体框架&自我跟踪实体与POCO [英] Entity Framework & Self-Tracking Entities vs POCO

查看:199
本文介绍了实体框架&自我跟踪实体与POCO的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想要使用实体框架4作为我的数据层,并希望将我的实体发送到另一个层,无论是通过WCF还是其他机制,然后想要更新实体并将其发送回来进行更新/删除/插入是否最好使用自我跟踪实体或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?

如果可能,我宁愿使用POCO对象,因为如果可能,我不想依赖于其他层中的实体框架,但我不知道如何困难它是将POCO重新连接到上下文。

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.

推荐答案

这是太多问题的组合,其中大多数已经在SO上被询问:

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

使用STE不会使您的上层依赖于EF,但如第二个链接中所述,STEs不是每个应用程序的解决方案。 STE有一些其他限制,例如甚至在服务器端你不能使用延迟加载,你在同一个密钥中的实体已经存在的情况下无法应用更改。

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.

使用POCO和WCF意味着您将与分离的实体一起工作,您将不得不说EF改变了什么。如果更新,这可能很简单单一实体,也可以仅更新单个实体的某些字段,但这可以是

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).

这篇关于实体框架&自我跟踪实体与POCO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆