Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think you're on the right track, but <em>in my opinion</em> your solution is not correct if you are, in fact, trying to decouple your view model from your data service. I am working on an app very similar to this right now. Different people have different ideas about mvvm, and this is just my personal approach that I have learned from trial and error (using visual studio):</p> <p>Start off by creating silverlight app project and hosting it in a .web project. The silverlight project will hold the views and view models. The view models should contain your models, not you're data service! However, the view models should have an instance of your data service to set the models. Where is my data service? I'm glad you asked :). Add another project, a WCF RIA Services Class Library. That is actually two projects, a ria service (server side) dll and a corresponding silverlight (client side) dll. You can add your entity framework or other database access code to the server side. After that, add a domain service to the server side project. Build it first (important) and then go to the client side ria service dll and create a data service class with your methods for the data service like so:</p> <pre><code>public void GetData( string filter, Action&lt;LoadOperation&lt;MyEntityType&gt;&gt; callback ) { var q = from e in _context.GetDataQuery() where e.SomeField.Contains(filter) select e; _context.Load(q, LoadBehavior.RefreshCurrent, callback, null); } </code></pre> <p>Your data service should not implement Inotifyproperty changed because that is the view models role! Reference the ria service client side dll in your silverlight project, and also reference the ria service server side dll in your web host project the view model should call this data service like so:</p> <pre><code>IEnumerable&lt;MyEnityType&gt; Model {get;set;} //NOTE: add notify property changed in setter! private void GetData() { _myDataService.GetData( _filter, loadOperation =&gt; { if ( loadOperation.HasError ) HandleError(loadOperation.Error); Model = loadOperation.Entities; } ); } </code></pre> <p>You can take it a step further and implement an interface for the data service if you really want to decouple them. Taking this approach allows for re-usability of your data service (in case you want a desktop app or phone app) I hope this helps clear things up!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload