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 remove an entity (Product) from my database. Products contain Comments, along with several other relationships. Comment has a One To Many relationship to Product (i.e. Products can have many comments) I am trying to remove a product like this:
When I commit this change, I receive error 1093 at this command:
When I run this directly, it works fine but I'm guessing something is different when it runs inside of this very large transaction. Any ideas? |
|
|
Sure enough after posting this, I noticed that out Comment entity has a One to Many relationship to itself for the purpose of supporting nesting comments. Setting the Removal Behavior on this relationship to Thanks, Bryan |
|
|
Yes there are a couple. First you need to ensure you perform the cascade at the database level to clean things up otherwise you may be left with orphaned entities. Secondly you will want to call IUnitOfWork.SaveChanges(true) as soon as possible after performing a Remove of an entity with a NoActionNoCheck association as this will flush the in memory entity cache and avoid you having any entities with stale references resulting from the original removal.
|
|
|
Thanks Jeremy. Is there a better way to accomplish this? |
|
|
Assuming you need the cascade delete to occur then I dont think so. Unfortunately this is just one of those annoying limitations of MySQL. I would personally look to leverage the database to handle the cascade deletion and compensate in the app for any dirty data via a flush of the UnitOfWork if needed.
|
|