Is DAL Layer needed in MVC3 architecture?

Possible duplicate:
Where to write database and business logic in MVC?

I just started with the MVC3 template. How do we access data in MVC3? Do we make 'MODEL' as the data access level or add another DAL layer and call it from the MODEL layer?

+4
source share
5 answers

Your model should be independent of data access materials, allowing you to change your DAL strategy in the future.

You should feed the model from DAL, but the model should not know how it is built, and, of course, should not have any database code in it.

If you take my approach, take a look at AutoMapper, a very useful tool for mapping data between DALs and model classes.

+1
source

When I was working with my last MVC3 project, my understanding from various samples (like GeekDinner) was that the Entity Framework serves as a data access layer.

0
source

Your model may be a directly mapped data access object, but it does not have to be. They could also be proxies to your backend DAL, which will always be the best option depending on your requirements and the durability of the project.

The way I usually process it for large projects is to have a separate namespace called Project.Entities , which contains my Entity Framework data models. My Project.Models will contain models that use entities as a backup storage for their data, and provide common methods (where necessary) for managing this data. This may not be the best way to do this, but it provides maximum flexibility and keeps data models separate from backup storage, allowing more abstraction. For example, you can always disable the basic data layer for storage in memory, a different DAL than the Entity Framework or something else.

For projects with less / temporary / testing, my Entity Framework data models will be direct in Project.Models and used directly, as it is faster and does not require much thought.

0
source

No, the model is not data access. A model is a class of classes for storing data, and it usually does not contain code, except, perhaps, to check the allowed values.

You get access to data from controllers. In this case, you do it completely up to you, and MVC is not worried.

0
source

A model is your view model, not your domain model.

If you want to perform DAL activity, I would tend to wrap it in a repository / service that can be injected into your controllers.

This prevents your controllers from bloating, and also allows you to make fun of your DAL level to modulate controller testing.

0
source

Source: https://habr.com/ru/post/1438623/


All Articles