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

查看:109
本文介绍了实体和模型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.

型号

我经常看,这基本上是实体的combimation重新present全套数据,比方说,一个客户的AddressList中的模式将结合实体客户,地址和个人可能。

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模式,这是一种模式,从而重新presents正是你可以在视图中的数据的术语。该视图模型是在应用层,并有验证,F.E.属性 ASP.NET MVC模型视图模型VS

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

从我的视线中,这些条件似乎都有些多余:视图模型具有明显的他的使用,否则认为会做所有的辛勤工作,以显示正确的东西。实体仅仅是重新presentation,因为我们从E​​F知道,但是如果结合这两种,在那里有他的使用模式?

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?

如验证,安全性等有东西要对视图模型完成的。你会使用该模型,当你有几百个小表,把实体和视图模型之间的另一个抽象?或在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),通常来自一个数据库。 pretty简单的类。

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

示范 - 任何业务对象,这是一个有点宽泛的术语。它可以是一个实体,你在你的项目等创造了一些自定义的类..这是pretty太多的一切,是不是一个观点也不控制器/视图模型。

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.

视图模型 - 某种模型和视图之间的调停人。它调制模型和视图之间的通信,例如应用验证,结合了更多的车型到一个更大的物体等,对于具有特定视图交互的目的。视图模型还负责事件处理(如按钮的鼠标点击),所以它暴露的命令绑定到(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视图模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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