MVC4 +的EntityFramework架构 [英] MVC4 + EntityFramework architecture

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

问题描述

继提出这里的德兴 MVC3和Entity Framework ,我试图为DAL,BL和网页创建不同的图层,使用MVC4 + EntitiFramework5。

Following the desing proposed here MVC3 and Entity Framework, I'm trying to create different layers for DAL, BL and web, using MVC4 + EntitiFramework5.

从@Davide Piras酒店报价

Quote from @Davide Piras

1 - ProjectName.Interfaces(类库,实体的接口);

1 - ProjectName.Interfaces (Class library, entities's interfaces);

2 - ProjectName.DAL(类库,允许甚至不知道EF唯一一个被使用,POCO实体实施项目1项使用另一个文件,你重新定义使用部分类相同的对象接口...);

2 - ProjectName.DAL (Class library, the only one allowed to even know the EF is used, the POCO entities implement the interfaces of project 1 using another file where you redeclare same objects using partial classes...);

3 - ProjectName.BL(类库,业务逻辑,引用上述1的两个项目和2);

3 - ProjectName.BL (Class library, Business logic, references the two projects above 1 and 2);

4 - ProjectName.Web(ASP.NET MVC应用程序,presentation层,引用两个项目1和3但不2);

4 - ProjectName.Web (ASP.NET MVC application, Presentation Layer, references two projects 1 and 3 but NOT 2);

我有BL和DAL之间的连接上一个疑问。 DAL知道EF,BL shoudln't ..但如何实现它?我的意思是,我创建了重新present我entitis两个层的类(这似乎有点重复给我..即使BL我会添加验证和其它某些材料),但我怎么揭露数据库值BL?

I have a doubt on the connection between BL and DAL. DAL knows EF, BL shoudln't .. but how to implement it? I mean, I created the classes that represent my entitis on both the layers (and this seems a bit a duplication to me .. even if in BL I'll add validation and other sutff), but how I expose the database values to BL?

在默认MVC4解决方案,我有

in the default MVC4 solution I have

 DbSet<Entity> entity

这是我可以查询(.Find等)。我想我需要他们在我的B1图(IQueryable的?IEnumerable的?Isomething?)

that I can query (.Find, etc) .. I suppose I need to map them in my BL (IQueryable? IEnumerable? Isomething??)

compltely迷茫..任何帮助是AP preciate

compltely confused .. any helps is appreciate

推荐答案

当你说话DAL和EF的线条可以变得有点模糊。在某些情况下,你的可以考虑EF的DAL 。但我通常不具备的BL直接访问EF和抽象到一个更高的层次,这样你就可以轻松更换EF为你的 ORM 如果需要的话。我使用库设计模式进一步抽象EF。其他的优势这种模式是,它可以更容易地进行单元测试,你可以使用依赖注入。我还使用工作设计模式的部门处理系统中的交易。所以,是信息库和DAL的工作部分的单位或只是EF。这可能是值得商榷的,我知道再与试图定义DAL关心自己。下面是我会建议使用在MVC 4项目的图层。

The lines can become a little blurred when you speak of DAL and EF. In some cases you could consider EF the DAL. But I usually do not have the the BL access EF directly and abstract it to a higher level, so that you could easily swap out EF as your ORM if need be. I use the Repository Design Pattern to further abstract EF. The other advantage to this pattern is that it makes it easier to unit test and you can use dependency injection. I also use the Unit of Work Design Pattern to handle transactions in the system. So are the Repository and the Unit of Work part of the DAL or is it just EF. That is probably debatable and I know longer concern myself with trying to define the DAL. Here are the layers I would recommend using in an MVC 4 project.

应用程序或领域层是你的BL层。我倾向于纳入该层中服务层使用概念,我还没有看到任何好处还在分离了出来。但也有在顶部加入该层的选项。

The Application or Domain Layer is your BL Layer. I tend to incorporate concepts used in the Service Layer in this layer as I have not seen any benefit yet in separating it out. But there is the option of adding this layer on the top also.

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

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