This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi! I`ve got a simple schema - Customer and Orders (ConcreteOrder inherits Order and ClassTableInheritance is used). The schema is attached. I build an object tree, add it to a unit of work and try to save changes: using (var uow = _context.CreateUnitOfWork()) Then I get an exception: The INSERT statement conflicted with the FOREIGN KEY constraint "FK__Orders__Customer__182C9B23". The conflict occurred in database "Foo", table "dbo.Customer", column 'Id'. Here is the sql statement: INSERT INTO Orders .... INSERT INTO ConcreteOrders .... INSERT INTO Customer .... We can see, that LS tries to insert Order and ConcreteOrder first and then insert Customer. But Order has a foreign key to Customer, so we get the error. But, if we use SingleTableInheritanse with Order-ConcreteOrder hierarchy, LS will use correct order of insert - first Customer, then Order. Is it a bug? Thanks.
|
|
|
Hmm, I have tried this with the equivalent classes from our standard CTI test suite and the insert order appears to be correct and I don't get a foreign key exception. I think we shipped you an update recently so it's probably not that you're on an older version, right? Could you maybe provide us with a minimal buildable project (NUnit test fixture or console application) that exhibits the error, so we can figure out what is different between your hierarchy and our test suite? Thanks! |
|
|
Hi, Ivan! I`ve used the last nightly build (20.10.2011), but, unfortunately, still got the exception. There is a simple project in attachment. |
|
|
Hi Dmitriy, Thanks for the repro. It seems we have a bug which is a bit sensitive to the exact order in which entity types are introduced. If you run the following code: var dummy = new ConcreteOrder(); before you first use the Customer type, then your code runs successfully. (The idea is that this tricks LightSpeed into reading the types in a slightly different order which avoids the bug.) You only need to do this once, when your app domain is starting up. For example, from your Application_Start event for Web applications or from Main for rich client applications. We'll try to fix the underlying bug but there are some tricky issues relating to intra-hierarchy associations so I would advise you to implement the workaround rather than waiting for a fix. |
|