No "include" available on LoadSelectAsync, LoadSingleByIdAsync, etc

I just noticed the include parameter isn’t available on the async methods LoadSelectAsync, LoadSingleByIdAsync, etc like it is on the sync versions. Is this a design decision that was made or you just haven’t gotten to it yet? If you need it done, I could give it a shot and submit a PR for it.

They should have feature parity so it’s just an oversight, but yeah feel free to have a stab at it :slight_smile:

Awesome, will do. What’s your opinion on parameter order in one such as…

public static Task<List<T>> LoadSelectAsync<T>(this IDbConnection dbConn, SqlExpression<T> expression, CancellationToken token = default(CancellationToken))

To me, it kind of makes sense to have the new string[] include = null parameter before the token so that the async version is the same as the sync version except for the addition of the token parameter at the end. But, this would be a breaking change for existing people who aren’t currently explicitly naming their token parameter. I’ll add it before or after token, whichever you think is a better design.

Yep should always be before the cancellation token and match the other async API’s

1 Like

This may be a dumb question and forgive me if it is (I’m fairly new to NUnit)…but I’ve added a unit test for this to ServiceStack.OrmLiteV45.Tests but can’t get it to show up in the Test Explorer. It looks like it’s not loading any of those tests in that project. How do I need to hold my mouth to get those to load?

Not sure, it should just show up, are you using the R# NUnit test runner? If you are try running the test from the marker icon left of the [Test] attribute.

Nah, I don’t have a license for Resharper. I am just using the official NUnit test runner extension. I’ll figure something out.

Haven’t used a different NUnit runner for years, but I’m assuming it’s looking at the .dlls so I’d expect it will turn up after a build, maybe needs a restart.

Got it showing up (was architecture settings difference within “Test Settings”). However, my test is failing, but on the SaveAsync which I haven’t touched. So I created a simple test for just SaveAsync and it fails. Note that it only fails if references: true is passed.

[Test]
public async Task Can_save_references_async()
{
    var customer = new Customer
    {
        Name = "Customer 1",
        PrimaryAddress = new CustomerAddress
        {
            AddressLine1 = "1 Humpty Street",
            City = "Humpty Doo",
            State = "Northern Territory",
            Country = "Australia"
        },
        Orders = new[] {
            new Order { LineItem = "Line 1", Qty = 1, Cost = 1.99m },
            new Order { LineItem = "Line 2", Qty = 2, Cost = 2.99m },
        }.ToList(),
    };

    try
    {
        await db.SaveAsync(customer, references: true);
    }
    catch(System.Exception ex)
    {
        Assert.Fail();
    }
    Assert.That(customer.Id, Is.GreaterThan(0));
}

This test fails inside the catch with an NRE and a stack trace of…

Result StackTrace:	
at ServiceStack.OrmLite.Tests.LoadReferencesTests.<Can_save_references_async>d__6.MoveNext() in C:\Users\robert\dev\Open Source\ServiceStack.OrmLite\tests\ServiceStack.OrmLiteV45.Tests\LoadReferencesTests.cs:line 170
at NUnit.Framework.AsyncInvocationRegion.AsyncTaskInvocationRegion.WaitForPendingOperationsToComplete(Object invocationResult)
at NUnit.Core.NUnitAsyncTestMethod.RunTestMethod()
Result Message:	Exception saving customer with SaveAsync and references:true => Object reference not set to an instance of an object.

If I change the test above to references: false it passes. Does this fail for you?

Yep failing for me as well, will look into it.

Awesome, thanks. In the meantime, I’ll change my test to use separate SaveReferencesAsync calls just like Can_Save_and_Load_References_Async does.

PR submitted with passing test. Thanks for the help!

Hey Robert, thx for the PR, but noticed it too late, can you pull the latest from master and resubmit the PR please?

No problem…done:

Awesome, CI tests all pass, thx!

My pleasure. Thankful to finally give back to the project.