Hi,
Just started with .NET,C#, ADO.NET, etc, etc, so possible something incredible trivial I'm missing here, in which case my apologies...
I've encountered an odd problem whereby I cannot add records to a BindingSource if that BindingSource is also used as the DataSource for a listbox/combo, etc. If I disable the data binding it works fine.
I've produced a minimalist example which produces the error: http://media.tanima.co.uk/dblistboxtest.zip
All I'm doing is:
private void button1_Click(object sender, EventArgs e)
{
SoundingHeader sh = new SoundingHeader();
sh.name = "New Identifier";
soundingHeaderBindingSource.Add(sh);
db.SaveChanges();
}
And the call to SaveChanges() raises InvalidOperationException...
" The changes to the database were committed successfully, but an error occurred while updating the object context. The ObjectContext might be in an inconsistent state. Inner exception message: AcceptChanges cannot continue because the object's key values conflict with another object in the ObjectStateManager. Make sure that the key values are unique before calling AcceptChanges. "
The database is (in my example) as simple as pie - that one table, no triggers, and the primary key is definitely flagged as the Identity with the framework designer. If I add the record to 'db' directly, it works fine, but then my listbox won't update without recreating the BindingSource (which seems to totally defeat the object of having one afaics).
I'm running VS2010 Beta1, which may be the cause, but skipped out 2008, so that's the only version I have with the entity framework.
Any ideas? Cheers, Matthew.