ChuckJ に同意します。通常、DomainContext はビュー モデルの一部を形成します。たとえば、製品カタログを検索できる検索ページがあるとします。これが私が物事を構造化する方法です:
サーバー上:
class Catalog : DomainService {
IQueryable<Product> GetProducts(string keyword) { ... }
}
生成された DomainContext:
class Catalog : DomainContext {
EntityList<Product> Products { get; }
void LoadProducts(string keyword);
}
私が書くビューモデル:
class SearchViewModel {
Catalog _catalog = new Catalog();
public IEnumerable<Product> Results {
get { return _catalog.Products; }
}
public void Search(string keyword) {
_catalog.Products.Clear();
_catalog.LoadProducts(keyword);
}
}
そして最後に、xaml で、UserControl の DataContext を SearchViewModel のインスタンスに設定し、ItemsControl を Results プロパティにバインドします。選択した ViewModel パターンを使用して、ボタンのクリックを検索にバインドします (これは事実上、SearchViewModel が公開するコマンドです)。個人的には、次のようにSilverlight.FXで作業したことが好きです。
<Button Content="Search"
fxui:Interaction.ClickAction="$model.Search(keywordTextBox.Text)" />
そして最初にここに示されているように。
Chuck が言及しているように、ビュー モデルには実際に他の状態がある可能性があります。選択した製品の詳細。
それが役立つことを願っています! これについては、近いうちにブログで詳しく説明します。