0

I am trying to create a WPF project with MVVM and ADO.Net Entity Framework. I do have a few questions though.

  1. Do i create the Entity Framework Model in the Model Folder of the MVVM Design?
  2. Or do i have to create a new project for each item of the MVVM Model(i.e Views Project as a WPF Project,Model Project as a class libraray, ViewModel project as a class library)?
New Developer
  • 123
  • 1
  • 10

2 Answers2

0

It doesn't really matter where you put stuff, but yes I usually put all my EF or Linq-Sql stuff in a Model folder as they will usually house all of my model classes anyway and it keeps it all together. It is a bit of a grey area though, because it's also doing DataLayer stuff, so just bear that in mind too.

Regarding your 2nd point, no. The Model, View Models and Views should all be in the same project.

Take a look at this for some guidance on MVVM.

HAdes
  • 16,713
  • 22
  • 58
  • 74
  • 2
    The model should not be in the same projet as V and VM – Louis Kottmann May 16 '12 at 15:52
  • Hades - Do i have to create interfaces for each entity on the ADO.Net Entity framework as described in this article(http://www.silverlightshow.net/items/WCF-RIA-Services-Part-4-Integrating-with-the-Model-View-ViewModel-Pattern.aspx)? How do you work with entities into the view model? – New Developer May 17 '12 at 16:35
  • @Hades You should put Models in a seperate project so you can reuse those Models in another application too. – Mert Akcakaya Jul 12 '12 at 19:32
  • @Mert What if the model is very specific and never going to be used in another project? Plus you could possible also share' classes between projects if using a central version control system. There shouldn't be any hard and fast rules with this tbh, it's all just guidance. – HAdes Jul 13 '12 at 16:56
  • @NewDeveloper I don't. I either bind directly to the entity in the model, or expose it via a prop on the vm. – HAdes Jul 13 '12 at 16:59
  • @HAdes, It is always better to think about maintainabilty. You can say from the begginning that the model will be used for only a single application but then changes may happen. It does not hurt to put it into another project and develop & compile and deploy it as a seperate assembly. Otherwise we can always write a giant class and put everything from UI to DAL into it, but it does not make sense. – Mert Akcakaya Jul 14 '12 at 20:10
  • @Mert, in a way it could 'hurt to put into another project' if you go in an change something that works for 1 project but not in another. Also, if that change is really needed, you will most probs need to recompile the app referencing it, which makes it tied to it anyway. And we certainly don't want to get into a situation with hundreds of dlls each referencing other dlls etc etc, taking us back to dll hell. Although, as I said there's no hard rules for this stuff so depends on each situation, but the key is simply decoupling code, certainly not putting everything into 1 giant class. – HAdes Jul 18 '12 at 13:57
  • @HAdes, Ofcourse, I am trying to give ideas to let people decide best for their specific case. Discussing creates a better understanding about pros and cons of both approaches. One should decide which way to go based on their specific cases. – Mert Akcakaya Jul 18 '12 at 14:06
0

Do i create the Entity Framework Model in the Model Folder of the MVVM Design?

I usually create a separate project for the model which is storage ignorant (using POCOs) and also usage ignorant.

Or do i have to create a new project for each item of the MVVM Model(i.e Views Project as a WPF Project,Model Project as a class libraray, ViewModel project as a class library)?

If you are planning on having more than one type of view-model per model (e.g. one for WPF, one for a service, one for another service), then separate your view-models into their own assembly.

If your views only represent one model layer, then you can start out your views and view-models in the same assembly, then separate them if you get to a situation that you have multiple models under the same view (each with its own view-model).


You should also consider if you want the ADO.NET's model to be your main model (upon which you base your view-models), or if you want to treat it as a sort of view-model for storing (where the storage service is a sort of view).

Danny Varod
  • 17,324
  • 5
  • 69
  • 111