EDMX模型的不同代码生成项之间的本质区别是什么? [英] What are essential differences between the different code generation items for EDMX model?

查看:113
本文介绍了EDMX模型的不同代码生成项之间的本质区别是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试增加实体框架,所以我不觉得自己处于黑暗时代.我试图(到目前为止失败了)从生成的代码中了解可用代码生成项之间的本质区别.

I'm trying to ramp up on the entity framework so I don't feel like I'm in the dark ages. I tried (and have thus far failed) to intuit from generated code what the essential differences between the available code generation items.

POCO似乎将实体数据结构与将对象移入/移出数据存储区的对象隔离开来.

It seems POCO isolates the entity data structures from the ojbect that moves them in/out of a datastore.

我不确定什么是自我跟踪实体".我猜想跟踪部分指的是实现所谓的工作单元"模式,但是我不是正当的.还有更多的抓头,我想我想知道自我跟踪而不是什么?".

I'm not sure what a "Self-Tracking Entity" is. I'm guessing the tracking part refers realizing the so called "unit of work" pattern, but I'm not posative. And more head scratchingly, I guess I'm wondering "self tracking as opposed to what?".

推荐答案

POCO Generator

POCO代表普通旧C#(或CLR)对象. POCO独立于EF.它们只是遵循某些规则的类,但是您可以根据需要从自己的类型继承它们.它们也不包含任何与持久性相关的数据.

POCO Generator

POCO stands for Plain Old C# (or CLR) Object. POCOs are independent on EF. They are just classes following some rules but you can inherit them from your own type if you want. They also don't include any persistence dependent data.

当前,此类型最流行,因为它是当前架构方法的趋势,该功能具有POCO和轻量级功能.在某些情况下,使用POCO更为复杂,但这对于不了解持久性的体系结构来说是一个代价.

Currently this type is most popular because it is trend of current architecture approaches to have everything POCO and lightweight. In some situations using POCOs is more complex but that is a price for persistence ignorant architecture.

此生成器生成的实体类型与EDMX的默认代码生成方法相同.这些实体派生自EntityObject类,这使它们完全依赖于Entity Framework(我称它们为重型实体).这种依赖性为它们提供了一些附加功能或简化功能,但使它们难以在分离的场景中使用,它们的使用会导致上层与实体框架紧密耦合的体系结构,或者在实现更好的分离时会带来额外的复杂性.

This generator produces the same type of entities as the default code generation method for EDMX. These entities derive from EntityObject class which makes them fully dependent on Entity framework (I call them heavy entities). This dependency offers them some additional features or simplifications but it makes them harder to use in detached scenarios and their usage leads either to architecture with tight coupling of upper layers to Entity framework or to additional complexities when achieving better separation.

这种类型的实体是第一个EF版本中唯一支持的类型.甚至每个人都在使用POCO来实现更好的分离,这种类型是EF固有的,并且可能提供大多数功能.

This type of entities was the only type supported in the first EF version. Even everybody is using POCOs to achive better separation this type is native for EF and probably offers most features.

此生成器还使您的实体可序列化(使用DataContractSerializer).

This generator also makes your entities serializable (with DataContractSerializer).

这是非常特殊的POCO发生器类型.使用EF时,我们有两种情况. EF跟踪附加实体的附加方案,在EF范围外进行更改的分离方案,将实体附加到EF后,您必须告诉它您做了什么更改.典型的分离方案是Web服务,您在其中将实体传递给客户端,并且一旦客户端将它们传递回来,您就必须以某种方式同步更改,以便EF知道其必须生成哪些SQL命令. STE适用于这些独立的情况.它们是变更集模式的实现=他们跟踪自己的当前状态以及自自我跟踪开始以来所做的更改(就像旧的DataSet一样).

This is very special type of POCO generator. When working with EF we differ two scenarios. Attached scenarion where EF tracks changes made to entity and detached scenario where you did changes outside of EF scope and once you attached entity to EF you must tell it what changes you did. Typical detached scenarios are web services where you pass entities to the client and once the client passes them back you must somehow synchronize changes so that EF knows what SQL commands it must generate. STEs are for these detached scenarios. They are implementation of change set pattern = they track their current state as well as changes made since self tracking started (as old DataSet did).

这是一个理论.在现实世界中,STE具有大缺点,并且非常适合仅适用于非常特定的情况.

This is a theory. In the real world STEs have some big disadvantages and are suitable only for very specific scenarios.

又有一个生成器与Entity Framework 4.1一起安装.

There is one more generator which is installed together with Entity Framework 4.1.

此生成器与POCO生成器导致相同的实体.唯一的区别是使用了API. POCO生成器使用ObjectContext API,而DbContext生成器使用带有DbContext API的POCO(仅在EF 4.1和2011年6月CTP中可用).这些API之间的区别是选择.

This generator leads to the same entities as POCO generator. The only difference is used API. POCO generator uses ObjectContext API whereas DbContext generator uses POCOs with DbContext API (only available in EF 4.1 and June 2011 CTP). The difference between these APIs is matter of choice.

这篇关于EDMX模型的不同代码生成项之间的本质区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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