简体   繁体   English

什么是POCO的实体框架

[英]what is Entity Framework with POCO

What is the benefit of using POCO? 使用POCO有什么好处? I don't understand the meaning of Persistence Ignorance, what does this mean? 我不明白持久性无知的含义,这是什么意思? That the poco object can't expose things like Save? poco对象不能暴露像Save这样的东西? I can't wrap my head around this POCO that there's alot of buzz around. 我无法绕过这个POCO,周围有很多嗡嗡声。

What is the difference with the EF generated entities and POCO? 与EF生成的实体和POCO有什么区别?

POCO stands for "Plain Old C# Object" or "Plain Old CLR Object", depending on who you ask. POCO代表“Plain Old C#Object”或“Plain Old CLR Object”,取决于你问的对象。 If a framework or API states that it operates on POCO's, it means it allows you to define your object model idiomatically without having to make your objects inherit from specific base classes. 如果框架或API声明它在POCO上运行,则意味着它允许您以惯用方式定义对象模型,而无需使对象继承特定的基类。 Generally speaking, frameworks that work on POCO's allow you greater freedom and control over the design and implementation of your classes, because they have fewer requirements to work correctly. 一般来说,在POCO上工作的框架允许您更自由地控制类的设计和实现,因为它们对正常工作的要求较少。

Persistence ignorance means that, as much as possible, anything in your code operating at the business logic layer or higher knows nothing about the actual design of the database, what database engine you're running, or how or when objects get retrieved from or persisted to the database. 持久性无知意味着,尽可能地,在业务逻辑层或更高层运行的代码中的任何内容都不了解数据库的实际设计,正在运行的数据库引擎,或者何时或何时从中检索或保留对象到数据库。 In the case of the MEF, persistence ignorance is attained by working on POCO's and using LINQ to perform queries (ie, not requiring the user to create any SQL queries to retrieve the desired objects). 对于MEF,通过处理POCO并使用LINQ执行查询(即,不要求用户创建任何SQL查询来检索所需对象)来实现持久性无知。

It's an open question, but it's generally agreed that under most circumstances, the domain objects (or business objects - either way, the POCO's mentioned above) should be ignorant of persistence logic. 这是一个悬而未决的问题,但人们普遍认为,在大多数情况下,域对象(或业务对象 - 无论哪种方式,上面提到的POCO)都应该不了解持久性逻辑。 Meaning, instead of calling MyBusinessObject.Save() , you have a IO manager or adapter class, and you call Manager.Save(MyBusinessObject) . 这意味着,您没有调用MyBusinessObject.Save() ,而是拥有IO管理器或适配器类,并调用Manager.Save(MyBusinessObject) In this way, you avoid exposing persistence semantics on your business objects - you get better separation of concerns that way. 通过这种方式,您可以避免在业务对象上暴露持久性语义 - 您可以通过这种方式更好地分离关注点。

POCO = Plain old CLR Objects. POCO =普通的旧CLR对象。

Plain old CLR (ie C# or VB) objects means I can speak C# or VB the whole time I am writing my program, and not have to worry about esoteric database language like 普通的旧CLR(即C#或VB)对象意味着我在编写程序的过程中可以说C#或VB,而不必担心像我这样深奥的数据库语言

UPDATE MYTABLE SET MYFIELD1 = @MYPARAMETER1, MYFIELD2 = @MYPARAMETER2 BLAH BLAH

EF Generated entities == POCO connected (indirectly) to a database. EF生成的实体== POCO(间接)连接到数据库。

POCO class is the class which doesn't depend on any framework specific base class. POCO类是不依赖于任何框架特定基类的类。 It is like any other normal .net class that is why it is called “Plain Old CLR Objects” These POCO entities (also known as persistence-ignorant objects) support most of the same LINQ queries as EntityObject derived entities. 它就像任何其他普通的.net类一样,它被称为“普通旧CLR对象”。这些POCO实体(也称为持久性无知对象)支持与EntityObject派生实体相同的大多数LINQ查询。

POCO = Plain old CLR Objects POCO =普通的旧CLR对象

POCO Benefits: POCO的好处:

Technology Agnosticism is a bliss: This concept is usually revolving around PI (Persistence Ignorance), but it is not only that. 技术不可知论是一种幸福:这个概念通常围绕PI(持久性无知),但不仅如此。 Persistence Ignorance means that your entities should be cleared of any persistence related code constraints that a framework - usually an ORM - forces on you. 持久性无知意味着应该清除您的实体与框架(通常是ORM)强加给您的任何与持久性相关的代码约束。 This is, for eg if you have attribute level mapping where those attributes are not part of your domain but are there just because some framework wants them to be there, then your domain is not persistence ignorant. 这是因为,例如,如果您有属性级别映射,其中这些属性不是您的域的一部分,但只是因为某些框架希望它们在那里,那么您的域不是持久性无知的。 Sidar said here 西达尔在这里说

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM