The ViewModel could be seen as a wrapper around the model elements that are exposed in the view. In many of our examples, we only present a single model element.
But the ViewModel is not just a wrapper. It maintains LOGIC and STATE for the VIEW that it supports. It is UI aware without being bound to the specifics of the View. For example, the VM could receive and handle the "NEXT ITEM" request from the View. The VM doesn't know if the request was a result of a button click, link click, scroll, page-landing ... doesn't know and doesn't care.
The View has no idea whether the move to the next item will be allowed or what might be going on in the background. That's the VM's job. The VM could decide that the user should not move from the current item. Or it might decide to save changes to the current item first. Or it might present a confirmation dialog. Or it might send a message to the world that the user is moving to a new item.
The VM is responsible for all of these potential actions in response to a user gesture. The View shouldn't make such decisions.
And your Model - the Business Objects - don't make these decisions either! They don't know about users and moving from one item to another. They don't know when to save or not to save. They don't send messages to the UI; they don't even know that there is a UI.
The VM is task oriented. The VM says "I support my View by telling it what it should present and what the user can do within this View. I will handle all user requests from my View ... typically by delegating to other classes that carry out my instructions."
No, the VM is never an entity. If I understand properly, it won't be your "former EventObject or B.O." either
In sum: the VM is far more than a friendly facade over the Model or its entities.
It's worth reading about MVVM elsewhere. You might look at MVVM Light for a simple but useful example of the pattern.
--
You wrote: "In my VM I instantiate a EM (_mgr) and building a query. "
I do that in demos but not in real code. I have a firm rule: the VM never talks directly to an EntityManager. It always talks to an injected helper class that is responsible for acquiring the entities. That helper class is often known as a "repository".
The repository has access to the EntityManager and actually issues the queries. The repository exposes a method (e.g. "GetCurrentCustomers" ) that encapsulates the query. The VM would call upon the repository to fill a target collection (e.g., "customers = repository.GetCurrentCustomers()" ). The View binds to this VM collection.
My examples assume a synchronous data access approach for simplicity of exposition here. You'd need an asynchronous interface for a Silverlight client.
The separation is critical for testable and maintainable code.
It is also necessary to pour the query results into a collection that supports the View. The EntityManager returns a kind of List. In WinForms, WPF, or Silverlight you likely want a different kind of list ... one that is both richer and more specific to the binding framework ... like ObservableCollection<T>.
HTH
Edited by WardBell - 24-Sep-2010 at 10:39am