whoah
whoah

Reputation: 4443

Models Pattern in MVC

Is it a good practise to storage Models in this schema in solution?

  1. Models folder, where I have POCO classes (or objects with EF Data Annotations) and main file MyDbContext.cs
  2. ViewModels folder, where I storage all of ViewModels.

In ViewModels folder I have every single viewmodel class in separate XXX.cs file.
Should I do the same thing with Models folder and objects in this model? I mean, no one big file AccountModel.cs, but separate User.cs, ExternalUserProfiles.cs etc.



And at least question - when I have to use EF Fluent API with POCO pattern instead of Data Annotations EF?

Regards.

Upvotes: 0

Views: 75

Answers (1)

Ibrahim Najjar
Ibrahim Najjar

Reputation: 19423

Is it a good practise to storage Models in this schema in solution?

Yes it is, when the project grows large you can go further and replace each folder with a separate assembly.

Should I do the same thing with Models folder and objects in this model?

I recommend this too, this way you will have a parallel hierarchy and a better organization. As for MyDBContext I usually move that to the data access assembly but you can keep it with the domain model if you want and move it only when the data access layer get huge.

when I have to use EF Fluent API with POCO pattern instead of Data Annotations EF?

You can use whatever you feel comfortable with. The only downside of using Data Annotations is that it is tightly coupled to the actual domain objects. Another things is that Fluent API is capable of doing things not achievable with Data Annotations and allows better separation of concerns.

You can even use both of them at the same time, just use the best tool for job.

Upvotes: 3

Related Questions