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 guys, I have a bunch of child entities that have been soft-deleted that I would like to load for a read-only view. I understand that the IncludeDeleted flag only works for the aggregate root and doesn't extend to all the children that this parent tries to load. What would be the best way to solve this problem? Do you recommend using another column altogether (e.g. DeletedOnDate) and managing it manually? Or, is there a better way? Thank you! |
|
|
IncludeDeleted extends to any entities loaded in that query, so if you are eager loading the child entities as part of loading the parent then both will include deleted entities in any results returned. It does not "persist" to any lazy loaded children so these load normally and will filter any deleted entities. We would definitely recommend using the eager loading approach to handle this type of situation.
|
|
|
Thank you Jeremy. That's what I wanted to know. I am using LightSpeed 3.11 for now so I assume that this behavior works for it just as it works for version 4? Thanks again for your prompt reply! |
|
|
Yes, thats correct :) We have not made any changes to this, so it will work just the same in LightSpeed 4.
|
|
|
Hello, I am trying to eagerly load all with IncludeDeleted on an object by id that references n other entities via a many to many relationship. It doesn't appear to work. I can see the root entity is loaded WITHOUT the DeletedOn IS NULL clause, the intermediary (M2M) table is loaded WITHOUT the DeletedOn IS NULL clause but then the final table is HAS the DeletedOn IS NULL clause. Are you sure this works with Many to Many relationships? It seems to only work with many to ones. I'm probably doing something wrong. I am using an aggregate ("GetCommunicationAggregate"). All the relevant relationships defined are set to eager load using the same aggregate name.
The query expression was just: {ClientId = 39d915c1-b925-df11-bbbb-6cf04907333d}, T is Communication. Find has not been overridden - it's the lightspeed unitofwork implementation.
Here is the relevant diagram: |
|
|
I have actually just tried this with a simpler scenario (M:1) and it doesn't work either. I have an entity called Education that will reference ModeOfTransport. ModeOfTransport is set to load on aggregrate "GetEducationAggregate". Given:
I would expect any related ModeOfTransports to be loaded regardless of whether they were deleted or not. However that does not occur. The query for Education includes this in the SQL:
It's explicitly excluding deleted ModeOfTransport entities. Further the "Find" call craps out with a KeyNotFoundException. Which is the same behaviour as I get with the other many to many association.
Lightspeed version is 3.1.1891.14711 |
|
|
I have created a test project to isolate the issue: It contains two entities both with a PK called ID. One entity references another M:1 style. The two entities are Root and Related. Related has soft delete enabled.
The above always fails as the "Related" that the queried "Root" relates to has been soft deleted. The Find call fails ungracefully with an ambiguous KeyNotFoundException. I've attached the sample VS2010 solution. Expects the db to be local and the catalot to be called LSTest. DB Script - (or use the attached SQL 2008 R2 backup file)
I tried this with lightspeed 4.0.646.18138 as well and got the same result. What am I doing wrong? If I set IncludeDeleted to true in my test I get exactly the same result and sql generated is:
|
|
|
It works when there is no criteria (where clause) specified. Fails when there is. |
|
|
Hi Sam, Thanks for the detailed information on this. I have had a look at the repro you provided but I am not seeing a problem in testing here, you are however using a much older version of LightSpeed so its likely we have fixed something in the interim which is leading to the crash you saw. That said I have set up some test cases here which has surfaced an issue where the soft delete flag would be included on an association load despite the IncludeDeleted being set on the query so its likely that this is what you are running into. I have added in a fix for this which will be available in the next nightly build for 4.0. Let us know once you have had a chance to grab the nightly and review this against your actual model to see if this covers the issue you are seeing. If that doesnt cover the problem would you please be able to send through a small repro project which highlights the issue and I can debug this further locally.
|
|
|
Hello Jeremy, I was having this KeyNotFoundException using 3.1.1820.14537 AND the version 4 trial I downloaded yesterday. Yes there is an issue where the DeletedOn clause is being included in the association load, but there is also a separate issue where entities referencing deleted entities fail to load. They are sort of related, both around soft deletes. The root entity query loads up the "root" entity and it's related "related" entities. However it doesn't find the referenced "related" entity in the result and throws a keynotfoundexception. The problem is this occurs regardless of whether deletedon is included or not effectively meaning that any entity referencing a soft deleted entity is broken and cannot be loaded in any scenario. In my previous post I attached a 7zip file containing a test solution that reproduces the issue. If you run the provided SQL script and then run the test in the project, the test query issued in the test fails with a KeyNotFoundException. Did you run my test solution against the same version of lightspeed? Are all of the unit tests passing? We've verified this across 2 machines and with both v3.1.1 and the latest v4. We are using lightspeed in a very large application that has been stable in production for over 2 years. It would be a major risk to upgrade to Lightspeed v4 and could introduce a series of regressions that we cannot anticipate. Therefore we are very keen to stay with v3.1.1. Can you please try this test with v3.1.1820.14537? We would like to try and find a workaround that is possible with this version. Thanks Sam |
|
|
Hi Sam, Both tests are passing for me here. The version of 4.0 you mentioned earlier dates to Aug 11 2011 so I suspect there has been a fix for the issue you are running into made in between then and now. I have sent you an email to Sam K who should forward this on to you which has your test project and a copy of the Mindscape.LightSpeed + Linq assemblies I am using with the fix included which you can check against. Please ping me back via email as needed.
|
|