什么是实体框架与POCO [英] what is Entity Framework with POCO

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

问题描述

使用POCO有什么好处?我不明白持续无知的意思,这是什么意思? poco对象不能暴露像Save这样的东西?我不能把我的头围绕这个POCO,周围有很多嗡嗡声。



与EF生成的实体和POCO有什么不同?

解决方案

p> POCO代表普通老C#对象或普通老CLR对象,具体取决于你的问题。如果框架或API表示它在POCO上运行,则意味着它允许您定义对象模型惯用语言,而不必使您的对象从特定的基类继承。一般来说,在POCO上工作的框架允许您更好地自由和控制课程的设计和实施,因为他们的工作要求较低。



持续性无知意味着尽可能的,您的业务逻辑层或更高版本中的代码中的任何内容都不知道数据库的实际设计,您正在运行的数据库引擎,以及对象从数据库中检索或保留到数据库的方式或时间。 。在MEF的情况下,通过使用POCO并使用LINQ执行查询(即不要求用户创建任何SQL查询来检索所需对象)来实现持久性无知。



这是一个开放的问题,但是普遍认为,在大多数情况下,领域对象(或业务对象 - 无论是上述的POCO)都应该不了解持久性逻辑。意思是,您不必调用 MyBusinessObject.Save(),您有一个IO管理器或适配器类,并调用 Manager.Save(MyBusinessObject)。通过这种方式,您可以避免在业务对象上暴露持久性语义 - 您可以更好地分离这些关注点。


What is the benefit of using POCO? I don't understand the meaning of Persistence Ignorance, what does this mean? That the poco object can't expose things like Save? I can't wrap my head around this POCO that there's alot of buzz around.

What is the difference with the EF generated entities and POCO?

解决方案

POCO stands for "Plain Old C# Object" or "Plain Old CLR Object", depending on who you ask. 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. 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.

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 (i.e., not requiring the user to create any SQL queries to retrieve the desired objects).

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. Meaning, instead of calling MyBusinessObject.Save(), you have a IO manager or adapter class, and you call Manager.Save(MyBusinessObject). In this way, you avoid exposing persistence semantics on your business objects - you get better separation of concerns that way.

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

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