MVVM WPF application using WCF but "Model" missing - wpf

I'm creating a WPF application with MVVM framework. The data is then retrieved by accessing a WCF service exposing the data based on Entity framework model. Is there anything wrong with this? It seems that the "Model" portion of MVVM seems to be missing.

There is no issue with the design. Ef wcf part will act as model.
Silverlight-Application-with-MVVM-WCF-and-EF
Silverlight-with-MVVM-and-WCF

Related

WPF Data Validation? Anything out there better than IDataErrorInfo?

Is there a preferred practice to do Data Validation from within your ViewModel?
Looking into it some people seem to prefer IDataErrorInfo and some prefer to roll out their own validation frameworks (http://www.codeproject.com/KB/WPF/wpf_custom_validation.aspx)?
I'm wondering what the "Best Practice" is for Data Validation? Is there something that is accepted by the community when it comes to adhering to the M-V-VM guidelines?
Oh, and an FYI, I'm using Prism as my MVVM framework, but I don't think it has any laid out code for Validation assistance.
You might use the Validation Framework of the .NET Framework. It can be used with PRISM or any other MVVM Framework. The BookLibrary sample application of the WPF Application Framework (WAF) shows how to use it together with WPF Binding.

Sharing Silverlight and WPF Models with MVVM Light

I have a Silverlight class library which is a model in my MVVM app. I am using MVVM Light. How easy is it reuse that model in a WPF app and use the MVVM Light framework. The framework has different dlls for WPF and Silverlight so I guess there is incompatability of sorts. I was wondering if anyone could talk me through the options. Cheers, Chris.
The suggested option is to use the Project Linker, this tool synchronizes code over multiple projects, allowing you to maintain a Silverlight and WPF dll with one codebase.
I hope you mean model means data in WPF and Silverlight. If that is the case, you can expose the data using a Service. It can be any service like web service, WCF service or WCF RIA service. Since a service can be multi tenented you can have a Silverlight as well as WPF client accessing the same service.
If you are trying to share the ViewModels between Silverlight and WPF using MVVM light, I would suggest you have a look at the MIX 2011 video of the presentation by the creator of MVVMLight library Laurent Bugnion. This is called Deep Dive MVVM and is a very good session. In short you can share ViewModels between WPF and Silverlight by adding the file from one project to another as a "LINK".
Hope this helps

WPF Prism Entity Framework repository

I am building a WPF application using the PRISM guidance, I want to use the Entity Framework 4 for a data repository.
I have previously developed a Silverlight app, using Prism and WCF RIA Services which worked great as all my components are decoupled.
So what is the best way of getting data in my WPF application in a decoupled way.
Thanks for any advise
You might have a look at the BookLibrary sample application of the WPF Application Framework (WAF). It shows how to use the Entity Framework in a WPF MVVM application. However, it's not PRISM.

Silverlight 4 WCF RIA Services and MVVM is not as simple

[Disclaimer: I'm ASP.NET MVC Developer]
Hi,
I'm looking for some best practices with implementing MVVM pattern with WCF RIA in Silverlight 4.
I'm not looking to use MEF of IoC for locating my ViewModels. What I would like to know is how to apply MVVM pattern with Silverlight 4 and WCF RIA.
I don't want to use other stuff like Prism or MVVM Light toolkit. I found many examples on Internet showing how it is wonderful to drag and drop a datasource on the view and the job is done (it reminds me about my first VB6 developments).
I tried to implement MVVM with WCF RIA and it's not strightforward at all. If I understand, the MVVM should contain all the logic in order to unit test it in isolation but when it comes to combine it with WCF RIA it's another story. I have the following questions.
Can I use a generated metadata as model ? It would be easier to use it that if I write all from the scratch.
As I saw the only way I could get data is through DomainContext or through direct binding in the view (local ressource). I don't want the direct binding in the view, not testable at all. On the other hand I can't use DomainContext, it doesn't expose any single entity !!! All I have is the EntitySet that I can bind to datagrid. How do I bind a single Entity to the DataForm from the ViewModel ?
How do I udpate the model to the database ?
How do I navigate from one Entity to a collection of it's items. For example if I have a Company Entity I would like to show a DataForm to update an entity informations and a datagrid to show companies adresses. When saving a form, I would like to save an information to Company and an information to adress about which adress was selected as active.
Please help me understand how to do it well. Or maybe I should drop the WCF RIA and to do it with WCF from scratch ?
What do you think ?
You might be interested in this session. It explains how to use the MVVM pattern with RIA WCF Services.
I found this post useful:
http://www.astaticstate.com/2010/04/silverlight-4-using-mvvm-patter-ria.html
Some random answers...
I don't think that MEF is particuarly well suited for Silverlight. It's primarily for desktop apps, and could be adapted for other uses where the plug-ins are in the local file system relative to the app.
MVVM requires that you understand roles. The "view" is your XAML and code-behind. The code-behind should handle events from the user control, but very little more than that.
The ViewModel holds the data that the user control will bind to. Generally, the ViewModel is bound to the View as its DataContext, so that everything in the form can databind to properties in the ViewModel. The ViewModel must implement INotifyPropertyChanged, and raise property changed events for every property that the form databinds to.
You'll probably want to create an ObservableCollection, using an EntitySet as your source. This will handle INotifyCollectionChanged for databinding purposes. If the entities in the EntitySet also handle INotifyPropertyChanged, then you're in good shape on databinding for collections.
You can create a property for an individual entity, and databind to that, assuming that change notification is also implemented (both for entity members, and for the entity property).
RIA Services will regenerate the DomainContext on each build, which helps a little in keeping it in sync. It's intended to be a service layer above an ORM, though, so your ORM or other data mapping will still have to be maintained by other means.
I haven't looked at the final release of RIA Services, but I wasn't hugely impressed with the beta version. I'd rather have good entity classes defined on the server, and share them with the Silverlight project. It's not easy to set up, though, and requires some non-trivial WCF that doesn't rely on service referernces. (RIA Services final release may have cleaned some of this up, but the native WCF service reference in Silverlight is pretty much evil, mainly because it doesn't automatically recreate generated classes, and it hard-codes the URI for the server-side service.)
Metadata was another problem with RIA Services beta. It's easier to attach metadata attributes directly to your DataContract class and the individual DataMember properties, if you control the entity source. Again, that may mean not using RIA Services. Writing a separate metadata class, as was required for the RIA beta, wasn't a good solution.
I ended up not using RIA Services for Silverlight 3, and didn't regret it. Here's an excellent article on WCF and Silverlight. Although it says Silverlight 2, it's still on-target for any Silverlight release.
I do recommend MVVM Light. Source is available on Codeplex, if that's an issue. It provides messaging and commanding support, as well as a ViewModelLocator; while the latter takes a bit of work to understand, it's really a good extension to the basic MVVM model.
Hope this helps.....
Just thought I would let you know about a project I am working on - just got our first release done. Provides a great simple way to approach MVVM for Silverlight + RIA Services specifically. Simplifies a lot of the MVVM stuff, and provides some more controller-like functions with the Notifications class. http://slmvvms.codeplex.com/

MVVM: ado.net entity framework and model

I'm writing an application in wpf that uses MVVM. I wondered if I could use ado.net entity data model as a model in MVVM? Is it the same? If not, why?
Thanks for any help.
Regards,
Ev.
Sure, you can use the Entity Data Model as Model part of the MVVM Pattern.
You might have a look at the BookLibrary sample application of the WPF Application Framework (WAF).
This MVVM sample application uses Entity Framework data models as well and it is composed of various Views (UserControls).
as I understand, one can use the entity model. but you will finally have tied coupling with the entity framework. whenever you plan to exchange your model for eg. with another ORM, you'll have more work to replace the model.
better is to use a repository pattern for data access. with this pattern you have more flexibility in the end. similar question here

Resources