实体框架4网站架构

发布于 2024-08-28 17:44:26 字数 648 浏览 2 评论 0原文

您好,我接到的任务是使用 Entity Framework 4 创建一个 N-Teir 网站,但据我所知,我遇到了一些困难。

到目前为止,我的计划是拥有这些层

网站(应用程序层),
我所说的 Name.Framework (BLL),
名称.数据 (DAL),
Name.Entities(包含 POCO 类和 website/bll 中使用的其他结构类,
Name.Common(实用程序类)

我尝试使用存储库类,但正在努力使事情按照我的想法工作。下面是我遇到的一些问题的例子。

如果我想使用 .include() ,它会在我的存储库中还是业务层的责任? (我不知道这在 BLL 中如何工作)

.Order() 有同样的问题吗?据我了解,这需要位于存储库中或至少以某种方式传递到存储库中?!?

我应该使用 BLL 将上下文传递到存储库/数据层吗?目前,当我从数据层获取实体时,存储库中未引用的任何导航属性都会以“对象上下文已配置”返回,业务层是否仍应保留上下文等,以便不会发生这种情况?

或者总结一下这个帮助!!!

我需要在明天之前以某种顺序完成此任务(哎呀!),因为项目负责人想知道我们是否要继续使用实体框架或迁移到 NHibernate,因为我们内部对此有更多的了解。

感谢您的任何帮助或建议 马特

Hi I've been given the task of creating an N-Teir website using the Entity Framework 4 and am coming up against some brick walls, more than likely in my knowledge.

My plan so far was to have these layers

Website (application layer),
What I'm calling Name.Framework (BLL),
Name.Data (DAL),
Name.Entities (contains POCO classes and other struct classes used in website/bll,
Name.Common (utility class)

I've tried to use the repository class, but am struggling to make things work how I thought they would. Below are a few examples of what I'm getting stuck on.

If I want to use .include() would this be in my Repository or is this the responsibilty of the business layer? (and I have no idea how this would work in the BLL)

Same question for .Order()? As I understood it this would need to be in repository or at least passed into the repo in some way?!?

Should I be using the BLL to pass in the Context to the repository/data layer? At the moment when I get an entity from the Data layer any navigation properties that weren't referenced in the repo just come back with 'Object Context Disposed', should the Business layer still hold the context etc so that this wouldn't happen?

Or to summarize this HELP!!!

I need to have this in some sort of order by tomorrow (eek!) as the project leader wants to know if we are going to continue with Entity Framework or move to NHibernate as in-house we have more knowledge of it.

Thanks for any help or suggestions
Matt

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

短叹 2024-09-04 17:44:26

我自己在寻找类似的东西时发现了这个。目前没有对其进行太多研究,但看起来很有希望。

Looking for something similar myself I found this. Not looked into it too much at the moment but looks promising.

蓝海 2024-09-04 17:44:26

我目前正在使用 EF4 Code-Only 开发一个 Web 爱好项目,该项目具有以下结构([名称] 是我的项目的名称):

  • [名称].Web - ASP.NET MVC 2 项目
  • [名称] .Web.Models - 自定义视图模型,以及来自我的实体对象
  • [name] 的 AutoMapper 映射。Models - 我的 POCO 类和存储库
  • [name] 的接口。DataAccess - 一些与数据访问相关的接口,例如 IUnitOfWork
  • [name].DataAccess.EF - 所有实体框架相关的类和接口

我还有一个针对上述每个项目的测试项目,以及几个带有测试帮助程序和扩展的项目。

值得一提的是,这个爱好项目的部分目的是让我学习如何使用 EF4 和我自己选择的一些设计模式(在这个项目中涉及 EF 的模式是存储库模式和工作单元)图案)。另一个部分目的是建立一个可以在以后的项目中重用的代码库,这影响了我的应用程序中项目之间的划分 - 例如,如果我不关心重用,我可能会将所有数据访问相关的类放在一个项目中,而不是两个项目中。

I'm currently working on a web hobby project with EF4 Code-Only, where I have the following structure ([name] being the name of my project):

  • [name].Web - An ASP.NET MVC 2 project
  • [name].Web.Models - Custom view models, along with AutoMapper mappings from my entity objects
  • [name].Models - My POCO classes, and interfaces for repositories
  • [name].DataAccess - Some interfaces related to data access, for example IUnitOfWork
  • [name].DataAccess.EF - All Entity Framework related classes and interfaces

I also have a test project for each of the above, plus a couple of projects with helpers and extensions for the tests.

It might be relevant to mention that part of the purpose of this hobby project is for me to learn how to use EF4 with some design patterns of my own choice (the ones that concern EF in this project are the Repository Pattern and the Unit of Work pattern). Another partial purpose is to build up a code base that I can re-use in later projects, and this has affected the division between projects in my application - for example, if I wasn't concerned with re-use, I'd probably have all data access related classes in one project instead of two.

℡寂寞咖啡 2024-09-04 17:44:26

我已经实现了基本的 EF、poco、Repository、UnitOfWork 架构,主要遵循本文:

http://devtalk.dk/CommentView,guid,b5d9cad2-e155-423b-b66f-7ec287c5cb06.aspx

我发现它对这些工作非常有帮助。不知道它是否对您有帮助,但其他人可能对该链接感兴趣。

I've implemented a basic EF, poco, Repository, UnitOfWork architecture largely following this article here:

http://devtalk.dk/CommentView,guid,b5d9cad2-e155-423b-b66f-7ec287c5cb06.aspx

I found it to be very helpful in these endeavors. Don't know if it helps you but others might be interested in the link.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文