Bilal Fazlani
Bilal Fazlani

Reputation: 6967

Model View Controller. What is Model?

What is model ?

I am an ASP.Net WebForms developer. I have been studying MVC for couple of days.

I can understand the concept of Controller and View but What is Model ?

Is it Data ? Does it have to be with LINQ or we can use traditional stored procedures ?

Upvotes: 1

Views: 134

Answers (5)

Derek Beattie
Derek Beattie

Reputation: 9478

Is it Data ?

Generally it's data and behavior. When you go about designing your model I'd suggest forgetting about "database" altogether. The Domain Driven Design book has an excellent example of this.

Does it have to be with LINQ or we can use traditional stored procedures ?

Try and create your model to be persistent ignorant. Lots of answer mention a database but ideally the model shouldn't have any knowledge of how it's persisted. And in some cases some not all parts of the model will be persisted. Look at the kigg source. It shows a clear separation between the model and the persistence. It shows implementing EF and Linq as two different options.

IMO, The ASP.NET MVC in Action books do a great job of laying out the different parts of MVC and discussing the different "models", ViewModel vs Entity Model, etc.

edit: Maybe the question should be, In (Domain driven design || Data driven design), what is the model?

Upvotes: 1

Akash KC
Akash KC

Reputation: 16310

In abstract level, Model is all about interacting with database and data.

There is no hard and fast rule to get interact with database via LINQ or some other traditional stored procedures. It entirely depends upon the context.

BTW, when you follow Skinny Controller and Fat Model approach, the businesss logic may get into Model or you can develop Service layer to handle business logic But I prefer to have business logic in Model.

Upvotes: 2

Dillon Benson
Dillon Benson

Reputation: 4440

A model is the single, definitive source of data about your data. It contains the essential fields and behaviors of the data you’re storing. Generally, each model maps to a single database table.

Upvotes: 1

Rab
Rab

Reputation: 35572

1) Yes, It is related to data.

MODEL is an object representing data or even activity, e.g. a database table or even some plant-floor production-machine process.

2) and technically, you can get it through Linq OR Stored procedure.

Upvotes: 1

Shyju
Shyju

Reputation: 218702

Model means your domain model or data. It does not have to be necessarily LINQ objects. You can create POCO classes for your domain model and use any data access method to fill data to it. You may use LinqtoSQL or EntityFrameWork or Plain ADO.NET for that. It is completely upto you.

When you look for MVC samples, you mostly see sample code/ program with LINQ to SQL or EntityFramework. Those are ORMS to help the developer to avoid writing all that mapping code from DataReader to POCO classes.

Remember MVC does not worry about what the data access method is. MCV is a development pattern which separates these different concerns into different layers.

Upvotes: 2

Related Questions