Hi. I am looking for any existing code/implementations whereby SS traverses through an entire object graph and touches each element, that I can reference and adapt to remove all nested softdeleted records that have been loaded.
Internally, I’ve been writing some extension methods to facade all the load operations to ensure that they are consistent in terms of loading only non-soft-deleted items, e.g
/// <summary>
/// Handle SoftDeletable table selections. Use like:
/// var userRoles = Db.SoftSelect<UserAuthRole>();
/// </summary>
/// <typeparam name="TTable"></typeparam>
/// <param name="db"></param>
/// <returns></returns>
public static List<TTable> SoftSelect<TTable>(this IDbConnection db) where TTable : IHasSoftDelete
{
return db.Select(db.From<TTable>());
}
rather than Db.Select(). Then, i can easily see/detect places see where I might have accidentally left in logic that wouldn’t cater for soft deletes, because my logic would be using all (only) Db.SoftSomeOperation. So far so good.
As you’ve noted elsewhere, the Ormlite logic that currently supports SoftDeletions only operates at the root object level, and does not filter out the child records that have been soft deleted. So
var parentsIdGt10 = Db.LoadSelect<MyTableWithChildren>(x => x.Id > 10);
would potentially include child references that implement ISoftDelete and are softdeleted.
For now, I am not going to bother trying to modify the sql query builder logic to attempt to do this at the db layer, but I would like to write some generic library to traverse an object graph and remove all softdeleted items in an automated fashion in the application layer.
and guessing that would be a good place to start some sort of “given some object, now traverse through all its references, and that that’s references, etc, and remove any items that are IsDeleted==true” (i.e. to set a single softdeleted refernce property to null, and remove softdeleted items from child reference Lists, accordingly)?
Another possibility might be to examine some json serialization logic - do you have any suggested starting points other than those I just suggested? Somewhere you might already be doing something similar?