I am pretty new to working with XAML and LINQ and could really do with some help. I need to be able to create and then save new records to my database (bound to objects on my XAML view). I can currently load and existing record, make the changes and then save (see test example below), but not from scratch (and I've spent far too much time today trying to figure it out).
In short, I need to start off with an empty record, and then save it (basic stuff I'm guessing).
egwEntities db = new egwEntities();
private egw_addressbook mvm = new egw_addressbook();
private void GetData()
{
DataContext = mvm;
var result = (from o in db.egw_addressbook where o.contact_id == 16875 select o).FirstOrDefault();
if (result == null) return;
mvm.org_name = result.org_name;
mvm.hex_srv_start = result.hex_srv_start;
}
private void btnSave_Click(object sender, RoutedEventArgs e)
{
var abook = db.egw_addressbook.Local.FirstOrDefault(o => o.contact_id == 16875);
abook.org_name = mvm.org_name;
abook.hex_srv_start = mvm.hex_srv_start;
db.SaveChanges();
MessageBox.Show("Saved");
}