不建议使用微软实体框架自我跟踪实体 [英] Entity Framework Self-Tracking Entities not recommended by Microsoft

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

问题描述

虽然看着微软的网站上,我发现他们不再推荐使用自跟踪实体。

下面每一个环节是,提到不使用国营一个MS资源:

有谁知道为什么微软不再建议使用国营贸易?

解决方案

(注:由于我的MS不工作,这是所有的的猜想的根据自己的公开言论和过去的历史记录)<。 / P> 之​​类的

您发表的第一篇文章解释了原因,虽然不是很清楚:他们希望你使用一个更好的选择,并无意固定的或改善国营贸易。微软是把国营成早期失败的实验完事,类似RDO或远程或LINQ2SQL - 他们把东西出来,看看它如何工作,它只是没有

在一般情况下,它总是由Microsoft承认国营是一第一刺伤解决一个实际的商业问题,但它们显然不完整的。特别是,他们的真的不好在连接的对象图共享实体,他们不支持延迟加载,并有一些其他杂项的限制。

MS显然已经决定他们不会试图清除它们(注意,他们还去precated的POCO模板,出于同样的原因)。由于他们不打算修复或改善模板,他们希望人们停止使用它的新项目,并移动到了更好的替代品:

MSDN资料库

  

的DbContext发电机

     

此模板将生成简单的POCO实体类和上下文派生自的DbContext。这是推荐的模板,除非你有一个理由使用下面列出的其他模板之一。

国营存在主要是为了支持其中的实体正在断开和重新连接到它们的背景下,尤其是在序列的场景的情况下(WCF或web服务,例如)。在标准的实体框架对象,所有的更改跟踪的背景下已完成,并附加一个existig实体上下文是有问题的。国营贸易企业所做的过程更容易,但做几乎一切真的很难的成本。

这是我所看到的和经历有关的DbContext 这应该是一个更好的选择来解决这个问题,但它实际上并没有的复制的什么国营贸易一样。其中EF的重度使用者的一般的共识似乎是,序列化的EF实体终端到终端是一个非常糟糕的主意。相反,你应该使用的DTO和如 AutoMapper 的东西,你的DTO和EF对象之间的映射。

While looking at Microsoft's web site, I discovered that they no longer recommend using Self-Tracking Entities.

Each link below is a MS resource that mentions not to use STEs:

Does anyone know why Microsoft no longer recommends using STEs?

解决方案

(NOTE: As I don't work for MS this is all conjecture based on their public statements and past history).

The first article you posted "sort of" explains the reason, though not very clearly: they want you to use a better alternative and have no intention of fixing or improving STEs. Microsoft is putting STEs into the bin of 'early failed experiments', similar to RDO or Remoting or LINQ2SQL -- they put something out to see how well it worked and it just didn't.

In general, it was always acknowledged by Microsoft that STEs were a first-stab at solving a real business problem but that they were clearly incomplete. In particular, they were really bad at attaching object graphs with shared entities, they didn't support lazy loading, and had a number of other miscellaneous limitations.

MS has apparently decided they're not going to try to clean them up (notice that they've also deprecated the POCO template, for similar reasons). Since they aren't planning to fix or improve the template, they want people to stop using it for new projects and move on to the better alternatives:

MSDN data library

DbContext Generator

This template will generate simple POCO entity classes and a context that derives from DbContext. This is the recommended template unless you have a reason to use one of the other templates listed below.

STEs existed mostly to support cases where entities were being disconnected and reconnected to their context, especially in serialization scenarios (WCF or web services, for example). In "standard" Entity Framework objects, all of the change tracking was done in the context, and attaching an existig entity to a context was problematic. STEs made that process easier, but at the cost of making almost everything else really hard.

From what I have seen and experienced about the DbContext it is supposed to be a better alternative to solve this problem, though it doesn't actually replicate what STEs did. The general consensus among heavy users of EF seems to be that serializing your EF entities end-to-end is a really bad idea. Instead you should be using DTOs and something like AutoMapper to map between your DTO and EF objects.

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

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