实体框架POCO对象 [英] Entity Framework POCO objects

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

问题描述

我很难理解实体框架和POCO对象。这是我正在努力实现的。



1)通过让我的业务层使用我的DAL的界面,将DAL与业务层分开。可能使用Unity来创建我的上下文。



2)在我的DAL中使用Entity Framework。



我有一个域模型,其中包含我的业务层中的对象。我还有一个数据库充满了表,并不代表我的域模型。我使用ADO.NET POCO Generator扩展设置Entity Framework并生成POCO对象。这给了我一个数据库中每个表的对象。现在我想要能够说 context.GetAll< User>(); 并让它返回一个我的User对象列表。 User对象在我的业务层。这是可能吗?



这是否有意义,或者我完全失败了,应该重新开始?我猜想我需要使用存储库模式来实现这一点,但我不确定。



任何人都可以帮忙?

解决方案

4在n层架构中的复杂性:


  1. http://devtalk.dk/2009/06/09/Entity+Framework+40 + Beta + 1 + POCO + ObjectSet + Repository + And + UnitOfWork.aspx

  2. http://blog.keithpatton.com/2009/05/30 /Entity+Framework+POCO+Repository+Using+Visual+Studio+2010+Net+40+Beta+1.aspx


  3. http://www.simonsegal.net/blog/2010/01/ 11 / entity-framework-repositories-fetching-strategies-specification-and-mapping-using-nfetchspec-for-role-driven-development-part-1-4


I'm struggling with understanding Entity Framework and POCO objects. Here's what I'm trying to achieve.

1) Separate the DAL from the Business Layer by having my business layer use an interface to my DAL. Maybe use Unity to create my context.

2) Use Entity Framework inside my DAL.

I have a Domain model with objects that reside in my business layer. I also have a database full of tables that doesn't really represent my domain model. I setup Entity Framework and generated POCO objects by using the ADO.NET POCO Generator extension. This gave me an object for each table in my database. Now I want to be able to say context.GetAll<User>(); and have it return a list of my User objects. The User object is in my business layer. Is that possible?

Does that make sense or am I totally off and should start over? I'm guessing I need to use the repository pattern to achieve this, but I'm not sure.

Can anyone help?

解决方案

Examples how to put entity framework 4 in n-tier arhitecture in order of complexity:

  1. http://devtalk.dk/2009/06/09/Entity+Framework+40+Beta+1+POCO+ObjectSet+Repository+And+UnitOfWork.aspx
  2. http://blog.keithpatton.com/2009/05/30/Entity+Framework+POCO+Repository+Using+Visual+Studio+2010+Net+40+Beta+1.aspx
  3. http://danielwertheim.files.wordpress.com/2009/12/putting-entity-framework-4-to-use-in-a-business-architecture-v2.pdf
  4. http://www.simonsegal.net/blog/2010/01/11/entity-framework-repositories-fetching-strategies-specification-and-mapping-using-nfetchspec-for-role-driven-development-parts-1-4

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

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