asp.net的MVC模式VS实体框架模型 [英] asp.net mvc models vs entity framework models

查看:126
本文介绍了asp.net的MVC模式VS实体框架模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

难道在你的asp.net的MVC创建模型的最佳实践 - 模型文件夹。
使用这些模型与您的意见,并通过使用一个服务层,以适应我的模型的EF-模式。

Would it be best practice to create a model in your asp.net mvc - model folder. Use these models with your views and by using a service layer to "adapt" my model to the EF-model.

或者你使用另一种方法。这种技术途径的问题是,大多数时候我(自制)模型是EF-模型(未干)

Or have you used another approach. The problem with this approachs is that most of the times my (selfmade)model is a copy of the EF-model (not dry)

所以,有人可以解释我的原因是becomming很困惑你的看法使用什么型号。模型/视图模型/ Entityframeworkmodel ....

So can someone explain me what models to use with your view cause it is becomming very confusing. model / viewmodel / Entityframeworkmodel ....

解决方案:

感谢所有的答案猜猜我是此刻重构一些事情!

Thanks for answers all guess i am at the moment to refactor some things!

推荐答案

正确的做法是使用视图模型不同阶层和不同的持久性(实体)。通常的原因是,你往往需要一些额外的数据发送到一个视图(例如数据来填充下拉菜单,数据禁用某些字段等等),使用不同的验证或显示一个实体的唯一子集。

The correct approach is using different class for ViewModel and different for a persistance (entity). The usual reason is that you often need to send some additional data to a view (for example data to fill drop downs, data to disable some fields etc.), use different validation or show only subset of an entity.

我不纯粹。如果我看到我的视图模型是完全一样的实体,我直接用实体,但我会重构code一旦我需要在视图中的任何其他信息。大多数时候我开始与实体和我的观点,因为增量发展模式结束。

I'm not purist. If I see that my view model is exactly the same as the entity I use the entity directly but I will refactor the code once I need any additional information in the view. Most often I start with entities and I end with view models because of incremental development.

这篇关于asp.net的MVC模式VS实体框架模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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