Reputation: 55
I'm new to MVC and now working on a small project but actually I don't know how to organize my project specially I'm using database first approach and I'm wondering where to put Entity framework data model in Model layer or in data access layer. My project is divided to these layers.
Upvotes: 0
Views: 66
Reputation: 36
My suggestion would be to put views, controllers and view models in the main web project, EF models and data access in a data layer class library and your business layer in a third class library. It's debatable how many layers you really need for a small project but separating web/business/data is good practice and is helpful if the project grows.
Upvotes: 0
Reputation: 239250
Well, you've got too many layers for one, which is part of why you're getting confused. Model
and Data access
are the same thing. Your entities should coexist with your method of retrieving them and working with them. Your Business
layer could likely be rolled in as well, since "business logic" is often the same as "data access" logic when dealing with database-persisted objects.
Then, for what it's worth, you really shouldn't have a View Model
layer. View models should be inherently tied to the view(s) they serve, and as result, aren't really shareable unless the view itself is shareable. In other words, you could have your controllers potentially in a separate project, but your views and view models should always go together.
Upvotes: 1