I am new to mvvm, basicaly its my first attempt. At now I have a WPF window, ado.net to connect to my database, and wcf service to make connection between viewmodel and database. The problem is that I cant add data from my view to database. here some code My wcf methods:
[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();
}
}
A command for binding to button:
public ICommand AddClient
{
get
{
if ((addClient == null) && (CurrentClient != null))
{
addClient = new RelayCommand(() => this.client.ManageClientAsync(CurrentClient, EntityState.Added));
}
return addClient;
}
}
And xaml code for one of textboxes:
<TextBox HorizontalAlignment="Left" Height="28"
Margin="469,50,0,0" TextWrapping="Wrap"
VerticalAlignment="Top" Width="160"
Text="{Binding CurrentClient.Name, Mode=Default, UpdateSourceTrigger=PropertyChanged}"
/>
Direct problem is when I am filling the textboxes and clicking to add them, I am catching null reference exception here, at client parameter:
public void ManageClient(Client client, EntityState state)
What am I doing wrong?