Problem with EF4, SQLite, TPT hierarchy and batch insert
I've been strugglin开发者_JAVA百科g for a little while with the following issue using EF4 and SQLite ADO.NET provider:
I have a model with a TPT hierarchy: There is an abstract base entity (Source), then first level child entities (SingleSource and MultipleSource), and 2nd level child entities (e.g. FileSource under SingleSource).
In my application I'm creating FileSource objects, and adding them to my context. As long as I call context.SaveChanges() after each Add operation of a new FileSource, everything works fine but when I add several FileSources to my context and then call SaveChanges once to save them all, I get an update exception:
Unable to determine the principal end of the FK_Source_SingleSource_0 relationship. Multiple added entities may have the same primary key
I've noticed that when I create new FileSource objects, EF sets their Id to 0 for all of them even though it's an identity field (StoreGeneratedPattern=Identity on both SSDL and CSDL) and I suspect that's the reason why it's failing but i couldn't find any solution yet so any help would be greatly appreciated.
Thanks,
Simon
精彩评论