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
|
We have two datatables, Routes and Orders, with a one to many association between the two i.e. many Orders per Route. We need to be able to add the child Order to the database before the Route is assigned, so the child has no parent. We have manually named the Backreference to ParentRoute. We have tried several variations, the last being to set IsNullable in the Association Definition section to true. When calling uow.SaveChanges, we get an error: An exception of type 'System.Data.SqlClient.SqlException' occurred in Mindscape.LightSpeed.dll but was not handled in user code Additional information: The INSERT statement conflicted with the FOREIGN KEY constraint "FKOrdersParen__22AA2996". The conflict occurred in database "Warehouse", table "dbo.Routes", column 'Id'. Can you tell me if what we want to do is possible and the required configuration? Thanks |
|
|
You will want to use the IsNullable approach as this allows for no parent. Check that the underlying database schema allows nulls as that error would seem to indicate there is a value associated which doesn't have an matching parent row as per the FK.
|
|
|
We are having an issue using IsNullable. It does not seem to make a difference and a unit test that worked before is failing. The relationship between Route and Order has a ParentRouteId and ParentRoute in the Order entity as expected. When creating a Route and adding multiple Orders then adding the Route to the UOW, an error is thrown complaining that the ParentRoute is null. This can be fixed by assigning the Route object to the ParentRoute property of each Order during object construction. This step was not necessary during previous unit testing and changing the IsNullable property on the relationship does not make a difference. Is there some other configuration property that we may have changed that would affect this behavior? Thanks, John |
|
|
We have a site source code license and debugging into the source, the error occurs at line 1364 in Entity.cs: Utils.Action wireUpKey = () => entityHolder.AssociationModel.SetFKFieldModel(this, entityHolder.Value.IdInternal); System.NullReferenceException was unhandled
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=Mindscape.LightSpeed
StackTrace:
at Mindscape.LightSpeed.Entity.<>cDisplayClass3. |
|
|
Hi John, No there shouldnt be any configuration change that would impact this behavior. Have you updated LightSpeed recently? If so can you see what version the test was previously passing with and I can have a quick scan to see what code changes have been made between the two versions to see. Also if you are able to send us through a small repro project which triggers this that would help us greatly in helping track down the problem for you.
|
|
|
Hi Jeremy, First, I have to apologize as I found the answer and it was all us!! We are using Autofixture to generate anonymous objects in our tests. I was creating a small project to send to you and did the Movies/Comments database as in your Quickstart. Everything worked as expected! I moved a subset of our model to the test project and that failed as we have been seeing. On examining the child object, the ParentObject was null but the ParentObjectId had been populated by AutoFixture with an arbitrary integer. Telling AutoFixture to ignore ParentObjectId fixed the problem. Thanks for your help. Generating the small project to give as an example lead to the solution. Thanks, John |
|