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
|
I am trying to save a new Registry entity to a SQL Server 2005 database. The database has been set up by our business intelligence team so the id is an auto number which means that the IdentityMethod is IdentityColumn. There is a parent field which is a link to another Registry entity. Rather than setting the parent to null for top level Registry entities, the parent is set to a special Registry entity with the ID of -1. When I try to create a new Registry entity that has a parent with the ID of -1 I get a StackOverflowException and the web server dies. I am using MVC 4 and LightSpeed 4, any guidance would be much appreciated. I can't see any way to overcome this at the moment. here is my code
|
|
|
This shouldn't really happen unless the assignment is going to trigger a subsequent loads - presumably you dont have an entity with the Id of -1 in the database? :) If you look at the SQL activity either by using a profiling tool or attaching a logger to the LightSpeedContext, what is the SQL activity being generated? If this doesn't help you identify the cause locally could you please send us through a small project reproducing this - presumably you should be able to lift your existing code and model into a ConsoleApplication to trigger this?
|
|
|
Thanks for the fast reply Jeremy Unfortunately yes, we do have an entity with the Id of -1 in the database ... and it has a parentId of -1. I've tried attaching a logger to the LightSpeedContext but I don't get anything back for this, I'll have a look at the SQL box to see what is happening. |
|
|
Right, that will be the problem then :) Is there a particular reason you have you set the Id on the magic parent to be itself rather than null, unfortunately this is always going to lead to StackOverflowExceptions with LightSpeed if we try and propagate a change, its not valid to have an entity related to itself.
|
|
|
So after a few tries at getting this working, I have finally got a work around that is ok for right now. So getting rid of the self reference in the parent Entity didn't solve the problem, and there was no activity on the SQL Server apart from when the unit of work is created. I tried to get the source, to debug, but couldn't figure out how to attach the source to referenced dll. But a clue that I don't know is relevant or not is that the Entity being added to the unit of work had it's Id changed from 0 to -1, so it looks like there are two different entities with an Id of -1 or this new Entity was referencing itself. Anyway my workaround was to check for a ParentId of -1 and save the Entity with no Parent, and then save it immediately after with a ParentId of -1. |
|