DAL(实体框架)和Model层到MVC [英] Dal (with Entity Framework) and Model layers into MVC

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

问题描述

首先,我使用EF到达尔层(separeted从MVC项目,相同的解决方案)。从EF的EDMX文件生成的模型从型号层的实际模型?如果是这样,我怎么访问这些车型在MVC的查看层工作?我认为这是错误直接从视图访问数据层有这些模特的工作,如果我做的型号层我的模型,并翻译DAL的车型要到我的模型......它会被复制code。

First of all , I use EF into Dal layer (separeted project from MVC, same solution). The generated models from EF's EDMX file are the actual models from Model layer?? If so, how do I access these models to work in MVC's View layer? I think it's wrong accessing data layer directly from view to work with these models, and If I make a Model layer with "my models" and translate Dal's models into mine models... it'll be duplicated code.

也许我越来越不对劲,但大多数EGS的。与code第一个方法,我想不通这一点。

Probably I'm getting something wrong, but most of egs. are with code first approach, and I can't figure out this.

推荐答案

您是对你不访问访问从presentation层直接在DAL的模型。

You are right in your idea of not accessing access the Models in your DAL directly from your presentation layer.

要避免翻译当你的DAL对象成你的意见所使用的模型,你可以使用类似的 AutoMapper ,这是应该做的heavylifting你在完全相同这种情况。

To avoid duplicating code when translating your DAL objects into the Models used by your views, you could use something like AutoMapper, which is supposed to do the heavylifting for you in exactly that scenario.

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

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