Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I haven't found anything online in terms of a "Best Practice".</p> <p>Personally I think the following setup is good: <code>View &lt;= BINDING =&gt; ViewModel &lt;==&gt; DataRepository/DataAccessLayer (Async Calls)</code></p> <p>As far as keeping your ViewModel in sync with the DAL you can do a couple of things depending on what data is needed to be synced:</p> <ul> <li>Expose <code>ReadOnlyObservableCollection&lt;T&gt;</code>s for collections of your models and manage their backing collections internally (from within the DAL).</li> <li>For single items return a new instance of the item and load the item on the async completed event.</li> <li>Also, learn to love the EventAggregator (it's not overly complex -- Though, there are improvements to it online -- <a href="http://codepaste.net/woqq1d" rel="nofollow">EventAggregator Extension</a>). It helps a lot. It's better to use this to announce "working" and "completed" events.</li> </ul> <p>Basically, since the Service Reference Generator helps build Async calls for you, just work with that and use your DataRepository/DAL to manage the data internally exposing references to your ViewModels and the EventAggregator to announce Working/Completed.</p> <hr> <p>I should also say this... you can choose to make your DAL completely synchronous and have all async calls to/from it on the ViewModel since you'll probably want to expose some type of "IsWorking/Completed" properties to let the view know something is happening or it's done. I think the key is to ensure that you stick all asynchronousity on one layer (not the View though). Doing it on the ViewModel layer makes it more coding work building the async calls, but it's a lot cleaner. You're DAL only does things synchronously and does not have to publish completed/isworking events. In fact, I'd actually say this is the more common approach.</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