Entity Framework

Mar 14, 2012 at 10:31 AM

Hello.

Is there any solution to work with the EntityFramework with their objects as Models for the MVVM. Or maybe helpers to map objects to Models. Or something else?

Coordinator
Mar 14, 2012 at 10:39 AM

The Entity class does support IEditableObject, so in theory, it should work out of the box. However, this depends on whether the IEditableObject on the entity is implemented correctly by the team.

Mar 14, 2012 at 11:00 AM

Ok. I did not quite understand everything. Sorry. So is it correct when i say a class is abel to be a model when its support the IEditableObject?

  However, this depends on whether the IEditableObject on the entity is implemented correctly by the team.

And with "the theam" you mean micrsoft?

Coordinator
Mar 14, 2012 at 11:38 AM

Yes, as long as a model supports INotifyPropertyChanged and IEditableObject, it can be a catel model. And with the team, I indeed mean Microsoft (but the Entity Framework team).

Mar 14, 2012 at 12:25 PM

Do you think its better to map the EFObjects to own ModelClasses?

Coordinator
Mar 14, 2012 at 12:26 PM

I see no reason for that, but I am not familiar with all your functional requirements.

Mar 14, 2012 at 2:59 PM

I do not need to register the Properties in the DataObjectBaseClass?

So how do i have Access in the viewmodel to the model Properties, with the [ViewModelToModel] or the [Expose] Attribute?

 

 

 

Coordinator
Mar 14, 2012 at 3:12 PM

Exactly, the entity framework model completely replaces the need for the DataObjectBase. If the class would be rewritten at this time, its name would have been "ModelBase" (in the MVVM naming  conventions).

You have 3 options:

1) Make your model public => bind directly to the model (but then you have no freedom in the validation, etc)

2) Use the ViewModelToModel attribute => if you want to use the properties inside your view model

3) Use the Expose attribute => if you want to protect your model, but don't need to access the properties in your view model

Mar 15, 2012 at 7:45 AM

Ok. So i can use ViewModelToModel attribute and Expose attribute also for EntityObjects. Good.

Coordinator
Mar 15, 2012 at 7:47 AM

Exactly! We tried to keep everything as generic as possible, but still provide lots and lots of out-of-the-box functionality. And... the good thing is you can turn all automatic features off so you can use it as a very basic mvvm framework as well. But once you tasted all of the features, you don't want to go back ;)