How load data from DB/XML to Model in MVVM

Nov 2, 2011 at 8:54 PM

Hi I would like to know how correct initialize Model from DB in MVVM.

I use Caliburn.Micro Framework, for dependency injection I can use MEF or Castle Windsor and as ORM I can use Entity Framework or NHibernate.

I have some model class it can be POCO

 

public class SomeModel{}

 

Also I have some view model class

public interface IViewModelA
{
ModelA SomeModel{get;set;}
}

public class ViewModelA : ScreenViewModel, IViewModelA
{
 public ModelA SomeModel{get;set;}
}

I bind properties of SomeModel on view. I think this is not good view.

I would like to know how correct load data from repository (XML, DB-with ORM) to Model.

Create some another class for example ModelManager init view models properties here?

This sample is with Caliburn + MEF

 

public interface IManager{}

[Export(typeof(IManager)]
public class Manager :Screen,IManager
{
  //import dependencies with MEF   
  [Import]
  public IViewModelA VMA{get;set;}

  public void Init()
  {
   VMA.SomeModelA=//load from DB
  }

}

Or what is correct and common way? 

I would like see some simple sample from real world with Caliburn.Micro + ORM (NHibernate/ Entity Framework)+ IoC (MEF/Castle Windsor).

Thank you :)

Nov 3, 2011 at 7:56 AM

Have you looked at http://coproject.codeplex.com/ ?