Conditions that could cause SaveEntityAsync to return false?

Posts   
 
    
hostileant
User
Posts: 9
Joined: 14-Feb-2017
# Posted on: 10-Oct-2023 14:15:07   

Hi team,

Just wondering if you could provide any guidance on when the SaveEntityAsync function might return a false value?

Obviously connection issues, database deadlock scenarios all throw an exception, but what are the common scenarios for a false value being returned and no exception being thrown?

The reason I ask is I have a piece of code I've tracked down where we are calling SaveEntityAsync and occasionally the entity simply does not save. The code in question doesn't test to see if the return result is true, it is really simple, similar to below.

            using var adapter = new DataAccessAdapter() { CommandTimeOut = 600 };
            await adapter.SaveEntityAsync(inventoryBinLocation);

This code is part of a some code that, probably obviously, processes inventory transactions and is part of a larger loop when processing multiple items. We're using auditing and we're not even getting an entry in the auditor when the save event isn't occurring. You can see our auditor entries and it's one inventory item in a loop missing one audit entry and all the other ones around it behave as expected.

I'd estimate that these inventoryBinLocations are being saved about 20k times a day and I think about once every 3 to 5 days it is occurring. There are other entities aside from the inventoryBinLocation as part of the larger function that are successfully saving either side of this one, and as mentioned no exception being raised.

I'm going to start testing the result of the SaveEntityAsync function and if it's false, attempt to log some additional information about it but to be honest I was curious what circumstance false would be returned. If that is indeed what is occurring.

I took at a brief look at the function and it appears to be linked to the rows updated by the queryController that executes the sql as part of the PersistQueueAsync function? I could keep diving down that rabbit hole but I thought you might be able to provide some quick guidance before I do.

I checked back over the documentation and can't see any guidance that we should be checking for a true return on SaveEntityAsync, or what state we're left in should it return false.

We're using MSSQL 2019 Enterprise and C# on .net 7, using LLBLGen Runtime with Adapter, all standard templates etc.. We do use Auditing but we don't use the LLBLGen Validation or much else that should influence behavior to my knowledge.

Walaa avatar
Walaa
Support Team
Posts: 14954
Joined: 21-Aug-2005
# Posted on: 11-Oct-2023 02:44:31   

You are talking about a "Save" action, but could you please specify if this is an Insert or an Update? SaveEntityAsync will return false in case of an Update if the entity to be updated was not found in the database.

hostileant
User
Posts: 9
Joined: 14-Feb-2017
# Posted on: 11-Oct-2023 02:45:39   

This is an update, so is that the only scenario of a false return?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39625
Joined: 17-Aug-2003
# Posted on: 11-Oct-2023 09:22:52   

It will return false if the save action resulted in 0 rows affected, so no inserts or no updates. The situation of no inserts is likely never going to happen as it will only occur when the insert action actually failed due to an error.

Frans Bouma | Lead developer LLBLGen Pro