Using Studio Entity Framework in MVVM with other MVVM frameworks

ComponentOne Studio Entity Framework (SEF) can be used to build Model-View-View-Model (MVVM) applications with any other MVVM frameworks.

ComponentOne Studio Entity Framework offers several features to make your MVVM development easier:

      Simplifies MVVM programming

Given that SEF can be used to simplify MVVM programming, as seen in the Simplifying MVVM topic, it’s clearly a tool that can be used for MVVM.

      Helps create view model classes and alleviate code bloating

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 SEF is designed to alleviate in a way that is entirely compatible with other frameworks.

      Allows you to use any framework and live views

You can use any framework you like to assist your MVVM application development and simply call on SEF to provide 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 ComponentOne Samples\Studio for Entity Framework\OrdersDemo\Orders-EF-MVVM folder using the following paths, depending on your operating system:

Windows XP path: C:\Documents and Settings\<username>\My Documents\ComponentOne Samples

Windows 7/Vista path: C:\Users\<username>\Documents\.

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 SEF 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 SEF 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.

 


Send us comments about this topic.
Copyright © GrapeCity, inc. All rights reserved.