实体 vs 模型 vs 视图模型 [英] Entity vs Model vs View Model

查看:28
本文介绍了实体 vs 模型 vs 视图模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是花了一些时间阅读这些术语(我不怎么使用它们,因为我们没有任何 MVC 应用程序,我通常只说模型"),但我觉得这些意味着不同的东西,具体取决于关于上下文:

I just spent some time reading about this terms (I don't use them that much since we don't have any MVC applications and I usually just say "model"), but I have the feeling these means different things depending on the context:

实体

这个很简单,就是数据库中的一行:

This is quite simple, it is one row in the database:

2) 就数据库而言,实体是单个人、地点或关于可以存储哪些数据的事情.

2) In relation to a database , an entity is a single person, place, or thing about which data can be stored.

模型

我经常读到,这基本上是表示完整数据集的实体组合,假设客户的地址列表模型将结合实体客户、地址和可能的个人.

I often read, this is basically a combimation of entities to represent a full set of data, let's say an Addresslist-model of a customer would combine the entities customer, address and probably individual.

视图模型

MVVM 或 MVC 模式中的一个术语,它是一个模型,它准确地表示您可以在视图上看到的数据.视图模型位于应用程序层并具有用于验证的属性,例如ASP.NET MVC 模型与 ViewModel

A term in the MVVM or MVC patterns, which is a model, which represents exactly the data you can see on the view. The viewmodel is on the application tier and has attributes for validation, f.e. ASP.NET MVC Model vs ViewModel

在我看来,这些术语似乎有点多余:Viewmodel 显然有他的用处,否则视图将不得不做所有艰苦的工作来显示正确的东西.正如我们从 EF 中所知,实体只是表示,但是如果将这两者结合起来,那么模型有什么用呢?

From my sight, these terms seem all a bit redundant: The Viewmodel has obviously his use, otherwise the view would have to do all the hard work to show the right stuff. The entity is just the representation, as we know from the EF, but if you combine these two, where has the model his use?

诸如验证、安全等之类的事情必须在 ViewModel 上完成.当您有数百个小表在实体和视图模型之间放置另一个抽象时,您会使用模型吗?还是在 MVC 和 MVVM 实体和模型方面通常相同?

Stuff like validation, security etc. has to be done on the ViewModel. Would you use the model when you have hundreds of small tables to put another abstraction between the entities and the viewmodel? Or Are in terms of MVC and MVVM entities and models usually the same?

像往常一样,谢谢,周末愉快

As usual thanks and a nice weekend

马蒂亚斯

推荐答案

不同的人对这些术语的理解有点不同,但我是这样理解的:

Different people understand these terms a bit differently, but this is how I understand it:

实体 - 具有身份 (ID) 的对象,通常来自数据库.非常简单的类.

Entity - object that has an identity (ID), usually comes from a database. Pretty simple class.

模型 - 任何业务对象,这是一个比较宽泛的术语.它可以是一个实体,也可以是您在项目中创建的一些自定义类等.它几乎是所有不是视图也不是控制器/视图模型的东西.

Model - any business object, this is a kinda broad term. It can be an entity, some custom class you've created in your project etc.. It's pretty much everything that isn't a view nor a controller/viewmodel.

ViewModel - 模型和视图之间的某种中介.它调节模型和视图之间的通信,例如应用验证、将更多模型组合成一个更大的对象等,以便与特定视图进行交互.ViewModel 还负责事件处理(例如按钮鼠标单击),因此它将命令公开给您绑定到的视图 (WPF).

ViewModel - some kind of a mediator between a model and the view. It modulates the communication between the model and the view, for instance applies validation, combines more models into one bigger object etc., for the purposes of the interaction with the specific view. ViewModel is also responsible for event handling (button mouse clicks for instance), so it exposes commands to the view you bind to (WPF).

这篇关于实体 vs 模型 vs 视图模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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