MVC3和Entity Framework [英] MVC3 and Entity Framework
问题描述
我的问题是pretty简单:它是一个很好的做法,把在模型文件夹中的的.edmx
文件中的MVC3项目的Web应用程序? / p>
我的回答是pretty简单,不要弄乱presentation层(全MVC应用程序)与数据访问逻辑和数据建模。
有在Visual Studio解决方案最低的4个项目,从底部到顶部:
1 - ProjectName.Interfaces(类库,实体的接口);
2 - ProjectName.DAL(类库,允许甚至不知道EF唯一一个被使用,POCO实体实施项目1项使用另一个文件,你重新定义使用部分类相同的对象接口...);
3 - ProjectName.BL(类库,业务逻辑,引用上述1的两个项目和2);
4 - ProjectName.Web(ASP.NET MVC应用程序,presentation层,引用两个项目1和3但不2);
这简化当然的事情,根据我的经验,这是一个坚实的设计,有点overkilling对非常小的项目,但在长期的回报。
在我看来,MVC,型号的M是不是数据模型,是不是EF,是不是有做绑定到特定的数据库引擎ORM。
这个答案是主观的,当然还有是基于我个人的经验; - )
My question is pretty simple: is it a good practice to place the .edmx
file in the model folder in a Web application of an MVC3 project?
my answer is pretty simple, do not mess up presentation layer (Whole MVC application) with data access logic and data modeling.
Have at minimum 4 projects in your Visual Studio Solution, from bottom to the top:
1 - ProjectName.Interfaces (Class library, entities's interfaces);
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 (Class library, Business logic, references the two projects above 1 and 2);
4 - ProjectName.Web (ASP.NET MVC application, Presentation Layer, references two projects 1 and 3 but NOT 2);
this to simplify things of course, based on my experience this is a solid design, a bit overkilling for very small projects but pays off in the long term.
in my view, the M of MVC, Model, is NOT the data model, is not the EF, is not there to do ORM bound to the specific database engine.
this answer is subjective of course and is based on my personal experience ;-)
这篇关于MVC3和Entity Framework的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!