Tutorial :In MVC, does an ORM represent the model?

Question:

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?

Thank you.

Solution:1

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

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.

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.

Solution:2

If you'd like to have a look at a good real world implementation of MVC with an ORM, have a look at S#arp Architecture which is based on MS ASP.NET MVC, Nhibernate and the repository pattern.