DataSource for Entity Framework in WPF > Using Entity Framework DataSource in MVVM with other MVVM Frameworks |
Entity Framework DataSource (EF DataSource) can be used to build Model-View-View-Model (MVVM) applications with any other MVVM frameworks.
Entity Framework DataSourceoffers several features to make your MVVM development easier:
Given that EF DataSource can be used to simplify MVVM programming, as seen in the Simplifying MVVM|document=WordDocuments\C1DataStudio-WPF.docx;topic=Simplifying MVVM topic, it’s clearly a tool that can be used for MVVM.
There are a plethora of tools and frameworks that developers can use to aid them in their work with MVVM, but very few that can help them create view model classes. The majority are designed to help with tasks such as passing commands and messages between the view and view model. Creating view model classes and then synchronizing them with model data is left almost entirely to manual coding. This is the primary cause of code bloating in most MVVM applications and precisely the one that EF DataSource is designed to alleviate in a way that is entirely compatible with other frameworks.
You can use any framework you like to assist your MVVM application development and simply call on EF DataSource to provide live views|document=WordDocuments\C1DataStudio-WPF.docx;topic=Live Views to help you create view model classes.
To demonstrate these important points, we provide a sample based on the code from the well-known article by Josh Smith, one of the authors of MVVM, "WPF Apps With The Model-View-ViewModel Design Pattern" (http://msdn.microsoft.com/en-us/magazine/dd419663.aspx).
The sample can be found in the Documents\ComponentOne Samples\WPF folder.
Essentially all the files in our modified sample are the same as the originals (bar a few cosmetic changes) except one (ViewModels\OrdersViewModel.cs).
In this file, we build the view model class the EF DataSource way, using live views. You can see how many re-shaping functions are applied to model data to construct a view model, all done exclusively through LINQ. This made it easy and required little code. The best part is that it synchronizes automatically with model data when data in either of the two layers is changed - no synchronization code was necessary.
The fact that we only changed the way that the view model classes themselves were created (they are still derived from the original base class 'ViewModelBase') and made no other changes to the framework code that Josh Smith had employed in his original sample should serve as an example that EF DataSource is entirely compatible with other frameworks. You can continue to use your preferred frameworks when working with MVVM, but now you have an additional tool to make your MVVM development even easier.