我是mvvm的新手,basicaly是我的第一次嘗試。現在我有一個WPF窗口,ado.net連接到我的數據庫,以及wcf服務來建立viewmodel和數據庫之間的連接。問題是我不能將數據從我的視圖添加到數據庫。 這裏的一些代碼 我的WCF方法:與MVVM綁定的問題
[OperationContract]
public void ManageOrder(Order order, EntityState state)
{
using (var context = new SvLaserEntities())
{
context.Attach(order);
context.ObjectStateManager.ChangeObjectState(order, state);
context.SaveChanges();
}
}
[OperationContract]
public void ManageClient(Client client, EntityState state)
{
using (var context = new SvLaserEntities())
{
context.Attach(client);
context.ObjectStateManager.ChangeObjectState(client, state);
context.SaveChanges();
}
}
一種結合按鈕命令:爲文本框的一個
public ICommand AddClient
{
get
{
if ((addClient == null) && (CurrentClient != null))
{
addClient = new RelayCommand(() => this.client.ManageClientAsync(CurrentClient, EntityState.Added));
}
return addClient;
}
}
和XAML代碼:
<TextBox HorizontalAlignment="Left" Height="28"
Margin="469,50,0,0" TextWrapping="Wrap"
VerticalAlignment="Top" Width="160"
Text="{Binding CurrentClient.Name, Mode=Default, UpdateSourceTrigger=PropertyChanged}"
/>
直接的問題是,當我填充文本框並單擊添加它們,我在這裏捕獲空引用異常,在客戶端參數:
public void ManageClient(Client client, EntityState state)
我在做什麼錯?
實行的是它的客戶端或實體狀態一片空白?你可以發佈你的客戶類 – 2013-04-22 01:20:44