Ok, what I'm doing is (I think) rather simple.
I have a LINQ-to-SQL data context set up and one of the tables is Users. In the designer, it shows the class as "User" with the source as "dbo.Users". It's access is Public, and I can reach the database to retrieve and update just fine. The class is set to "Use Runtime" for the I/D/U operations.
The problem comes when I try to add a new record.
- I have the datagrid set to AutoGenerateColumns ="True"
- CanUserAddRows is set to "True"
- RowEditEnding event is set to a method.
When I add a record (SubmitChanges() on the data context), nothing happens. It simply does not do the insert. I've checked the local objects at a breakpoint and all indications are that it's indeed there and it does have the correct record that it should be adding.
But wait, there's more.
If I execute Users.InsertOnSubmit() and pass the datagrid's CurrentItem (casted to user), it gives me an error saying "cannot add an entity that already exists" BUT I find that the record has actually been inserted.
Does anyone have a clue?
(FWIW, the backend is SQL2K8 Express)
EDIT:
The code that gives no exception but doesn't add the record either:
private void UserGrid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
{
ctx.SubmitChanges();
}
and the code that gives an exception:
private void UserGrid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
{
ctx.Users.InsertOnSubmit((User) e.Row.Item);
ctx.SubmitChanges();
}