Hi. I am attempting to use the MSSQL softdelete functionality that you implemented at my request a while back (thanks!) but I am experiencing a crash with error "System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable “@1"” when using the LoadSelect() condition, specifically when querying the referential fields.
I have EventCategoryTbl with each record requiring a linked image FileTbl, both tables are softdeleteable. I initially added the Ormlite interceptor to add the IsDeleted==false condition to all my tables, then swapped it to explicit per-table declaration style while trying to debug this issue.
When I call either:
var categoryRows = Db.LoadSelect<EventCategoryTbl>();
or (as i saw in one of the sample snippets)
var categoryRows = Db.LoadSelect<EventCategoryTbl>(x => !x.IsDeleted);
I get errors as per the following (note the multiple, apparently duplicated IsDeleted conditions):
"SELECT \"FileId\", \"Name\", \"Extension\", \"FileSizeBytes\", \"RowVersion\", \"IsDeleted\"
FROM \"File\"
WHERE \"FileId\" IN (
SELECT \"EventCategory\".\"LinkedImageId\" \n
FROM \"EventCategory\"\n
WHERE (\"EventCategoryId\" <> @0) AND (\"IsDeleted\" <> @1) AND (\"IsDeleted\" <> @2) AND (\"IsDeleted\" <> @3))"
While trying to debug this, I referred to the GitHub source and attempt to run the tests locally on my machine because I can see here (https://github.com/ServiceStack/ServiceStack.OrmLite/blob/master/tests/ServiceStack.OrmLite.Tests/SoftDeleteTests.cs) that you test for this exact situation.
The test case Can_filter_deleted_products_reference_data() runs for me successfully, however, I notice that the test condition is currently set to check that Assert.That(vendors[0].Products.Count, Is.EqualTo(2));", but I think that should be returning only a single record, because one of the Products IS deleted?
So my problem is two-fold - I have a strange condition preventing me from using the softdelete with LoadSelect, and the test case that I am referring to to confirm the functionality doesn’t match my understanding of the functionality.
For reference, the two tables are declared as:
[Alias("EventCategory")]
public class EventCategoryTbl : IHasTimeStamp, IHasSoftDelete
{
[PrimaryKey]
public Guid EventCategoryId { get; set; }
[Required]
public string Name { get; set; }
/// <summary>
/// Link to the file record that contains any image related to this category
/// </summary>
[References(typeof(FileTbl))]
public Guid LinkedImageId { get; set; }
[Reference]
public FileTbl LinkedImage { get; set; }
[Reference]
public List<EventTbl> Events { get; set; } = new List<EventTbl>();
public bool IsDeleted { get; set; }
[RowVersion]
public ulong RowVersion { get; set; }
}
and
[Alias("File")]
public class FileTbl : IHasTimeStamp, IHasSoftDelete
{
[PrimaryKey]
public Guid FileId { get; set; }
public string Name { get; set; }
public string Extension { get; set; }
public long FileSizeBytes { get; set; }
[RowVersion]
public ulong RowVersion { get; set; }
public bool IsDeleted { get; set; }
}