在MVC中,ORM代表模型吗? [英] In MVC, does an ORM represent the model?

查看:124
本文介绍了在MVC中,ORM代表模型吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MVC中,ORM是与模型相同还是只是可以设计模型的方式?换句话说,只要获得数据,模型"就不在乎如何获取数据.或者,模型"是否意味着我的代码中不再像一堆表格后面的代码中那样有一堆SQL语句?还有吗?

In MVC, is the ORM the same as the model or just a way the model can be designed? In other words, the "model" doesn't care how you get data as long as you get it. Or, does "model" imply that I no longer have a bunch of SQL statements in my code like in code behind forms? Something else?

谢谢.

推荐答案

不,ORM是将模型映射到数据库,反之亦然的东西.

No, the ORM is the thing that maps your model to your database and vice versa.

要详细说明,您将在代码中创建模型以表示域模型(即问题域的各个元素),然后配置一个ORM(对象关系映射器)以将其映射到数据库. IE.生成SQL语句,该语句将根据您提供给它的模型对象更新数据库.

To elaborate, you would create your model in your code to represent the Domain Model (i.e. the various elements of your problem domain), then configure an ORM (object relational mapper) to map that to a database. I.e. Generate SQL statements that will update the database based on the model objects you give to it.

我可以理解一些混乱,因为有工具( LINQ to SQL 是一个),它实际上可以在设计器中为您生成模型类.这不是纯粹的ORM,例如 NHibernate ,您可以在其中提供ORM普通的旧对象和一些映射它使用(通常与反射结合)自动为数据库生成SQL语句的配置.

I can understand some confusion, because there are tools (LINQ to SQL being one) that actually generate model classes in a designer for you. This isn't pure ORM, like NHibernate, where you provide the ORM plain old objects and some mapping configuration that it uses (often in conjunction with reflection) to automatically generate the SQL statements for the database.

这篇关于在MVC中,ORM代表模型吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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