开发者

ASP.NET MVC - Remove dependency from DAL in GUI

I'm building a MVC web app that consist of 3 projects. One for the GUI, one for the BusinessLogic and one for the Data access.

For my Data access I have a generated file by EF and therefore I have a generated class named "Customer". To make validation attributes 开发者_运维知识库for this class I need to make MetaDataType (which needs to be done in the same namespace and therefore I'm bound to do it in the DAL layer) - by doing this I refer to the Data access layer from my GUI which spoils the whole idea of splitting the project up, because that my GUI now refer both my DAL and BL layer. Is there anyhow I can keep my GUI and DAL layers seperated but still be abe to use Validation attributes like [Required] and so on?

Thanks in advance.


If you're using .NET 4 (EF 2) you can generate POCO entities in a separate class library that can be shared across projects. That won't require a dependency to the DAL. See my previous answer:

ASP.Net Layered app - Share Entity Data Model amongst layers

Especially 3. POCO templates, including how to move to separate project: http://blogs.msdn.com/adonet/pages/feature-ctp-walkthrough-poco-templates-for-the-entity-framework.aspx


That's what ViewModels are about. But that means you will have a new set of DTO's for the view-controller communication... Which is a good thing IMHO, since your views should not know anything about the real domain model.

Regarding all distinct ways of making your views communicate with the model, please take a look at this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜