views:

42

answers:

1

Hello,

thats my table:

-- Original table schema CREATE TABLE [SchoolYear] ( [Start] datetime NOT NULL, [End] datetime NOT NULL, [Id] integer PRIMARY KEY ON CONFLICT ABORT AUTOINCREMENT NOT NULL );

my Entity in the EF designer has StoredGeneratedPattern set to Identity OR Compute and datatype is int64.

Everytime I insert a second SchoolYear object I get this error:

An object with the same key is already in the ObjectStateManager...

A: 

Check that the autoincremented property has the StoreGeneratedPattern attribute set to "Identity" in the SSDL part of the model, not in CSDL.
This is a known issue, the conceptual attribute is not taken into account while generating the code.

Devart
its set to Identity in both: SSDL + CSDL so it should work, but it does NOT!
msfanboy
without recognizing it earlier I have a new exception now:System.InvalidOperationException was unhandled:...The EntityKey property can only be set when the current value of the property is null...EDIT: Adding a new object to the context works for the first time when I check the table a new row is created, so the autoinc must work. Its something different now!
msfanboy
What a stupid error that was: (got again a new exception ...) I added always the same object to the context that seemed the problem. Now it works.I could have sworn, that EF v1 allowed me to add as many equal objects I wanted without throwing an exception, EF v1 just avoided adding the dupe object. Seems that changed in EF v4 ?
msfanboy
Try dotConnect for SQLite (http://devart.com/dotconnect/sqlite). I have made a test and autoincrement column is read successfully into the inserted objects.
Devart
my fault I did a stupid test scenario... so it provokated te same id...
msfanboy