0

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.

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

4 Comments

thanks! And about models and classes - how to storage it? All in one folder Models, or rather in subfolders like Models/Account or Models/Order? Regards.
@whoah Welcome, I usually use folders to store classes when they are in different namespaces, so I use Models/Account when my class is in namespace Models.Accounts, this gives better organization when there are a lot of domain model classes and namespaces.
lovely, thanks. And last question - how about naming ViewModel? Is it a good practise to name it in this way - ViewModels/Account/LoginViewModel.cs? I mean using suffix ..ViewModel.cs. Regards!
@whoah Yes I do that all the time, especially that I work with Caliburn.Micro and uses this naming convention to locate the view-models automatically for a given view.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.