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 a child/parent relationship in our model. The parent record can be deleted but it doesn't delete the children records (cascading deletes are off). Later on we access the children records and we want to see what the parent record was - but the parent record is not being loaded.
We are using soft deletes, so the records are never deleted - how can we access the parent record?
Craig
|
|
|
Query explicitly for the parent using the foreign key and specifying IncludeDeleted, e.g.: uow.Parents.IncludeDeleted().First(p => p.Id == child.ParentId) (In the core API, set query.IncludedDeleted = true.) |
|
|
Ouch, that's nasty :-(
It does work, but the problem is the children records are children of another record. In order to use the query we need to iterate through all the children and load the deleted parent - and since we are doing this using the MVC pattern it has to be done at the time the record is loaded.
Craig
|
|
|
[quote user="csut017"]Ouch, that's nasty :-( [/quote] If there's one thing modern archaeology has taught us, it's that when you dig up the dead, you must expect to face ancient curses and needlessly complicated death traps. And that parent entity is dead. Soft delete may be soft, but it's still a delete: it just means you can still examine the data through the management console or bring it back with an UPDATE script, rather than having to send someone over to Vaults R Us to dig through a pile of tapes. Seriously, we don't want to make it easy for you to load deleted entities. We want it to be a very explicit and conscious decision. If you're having to load deleted entities as part of your normal business logic -- if these entities remain an active part of your model -- that may indicate that you shouldn't be using delete semantics, but instead having some sort of "inactive" flag at the domain level. (Obviously, if what you need the deleted entity for is some sort of audit viewer or diagnostic/management console, then fair enough. I realise I'm speaking in ignorance of your usage scenario here.) If the "nasty" comment is more about performance, be reassured that the query I posted is only what a LightSpeed association traversal would be doing under the covers anyway. Okay, you don't get eager load; but on the other hand, you could do an IN query to pull all the parents back in one go. Hope this makes sense -- feedback welcome as always. |
|