lambda_method Projection Error with caching

Posts   
 
    
Posts: 12
Joined: 11-Aug-2017
# Posted on: 16-May-2024 21:35:05   

We have a project running: LLBLGen 5.10.1 - SelfServicing (Two Classes) - SQL Server 2017 - .NET Framework 4.8

In an ASP.NET web application, the following query works fine the first time it runs, however, refreshing the page or navigating to another page that runs that query again returns the error listed below:

var qf = new QueryFactory();
var q = qf.UserSiteRole
    .Select(() => UserSiteRoleFields.SiteId.ToValue<Guid>())
    .Where(UserSiteRoleFields.UserId == personId)
    .CacheResultset(60);

var sites = new TypedListDAO().FetchQuery(q);

The web app is using the MemoryCachedResultsetCache from the LLBLGen Contrib repo for caching.

[InvalidCastException: Specified cast is not valid.]
   lambda_method(Closure , ProjectionRow ) +86
   SD.LLBLGen.Pro.QuerySpec.DataProjectorToObjectList`1.AddRowToResults(Object[] rawProjectionResult) +51
   SD.LLBLGen.Pro.ORMSupportClasses.ProjectionUtils.FetchProjectionFromReader(List`1 valueProjectors, IGeneralDataProjector projector, IDataReader dataSource, Int32 rowsToSkip, Int32 rowsToTake, Boolean clientSideLimitation, Boolean clientSideDistinctFiltering, Boolean clientSidePaging, Boolean performValueProjectionsOnRawRow, Boolean postProcessDBNullValues, Dictionary`2 typeConvertersToRun, IRetrievalQuery queryExecuted) +2034
   SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.GetAsProjection(List`1 valueProjectors, IGeneralDataProjector projector, ITransaction transactionToUse, IRetrievalQuery queryToExecute, Boolean performValueProjectionsOnRawRow, Boolean postProcessDBNullValues, Dictionary`2 typeConvertersToRun) +288
   SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.GetAsProjection(List`1 valueProjectors, IGeneralDataProjector projector, ITransaction transactionToUse, QueryParameters parameters) +151
   SD.LLBLGen.Pro.QuerySpec.SelfServicing.SelfServicingExtensionMethods.FetchQuery(IDao dao, DynamicQuery`1 query, ITransaction transaction) +263

When I remove the .CacheResultset(60) then it works fine. Over, and over again. I had a go at trying to use .WithProjector but I couldn't get it working.

Your help is greatly appreciated.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39760
Joined: 17-Aug-2003
# Posted on: 17-May-2024 09:08:34   

The set is cached under the key with sql statement and parameter values, so another query which results in a different query wouldn't match the resultset (in theory at least).

When you put a breakpoint on the FetchQuery(q) method after you've fetched the query the first time, and then check what set is obtained from the memory cache (as you can step into that I think as you compiled that from source), I think the set contains empty Guids?

I think the set differs from the original hence the error (null value that's projected as a guid which causes the cast issue).

If you can, please compile the runtime framework from source, it's available on our website under the Extras section. (the DQE and ORM Support classes have to be compiled, you can remove the strong name requirement), or if you use Jetbrains tooling, you could step into FetchQuery, till you are at RetrievalQuery.PullReaderFromCacheIfRequired. that's the method which obtains the set from the cache.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 12
Joined: 11-Aug-2017
# Posted on: 17-May-2024 10:53:11   

Thanks Otis.

I ran through it, and realised that I made a big mistake! All the crazy configurations, environment variables, and abstractions, it was actually using the RedisResultsetCache (https://www.llblgen.com/TinyForum/Message/Goto/149483).

It seems like the problem is isolated to that RedisResultsetCache as using the SD.LLBLGen.Pro.ORMSupportClasses.ResultsetCache doesn't have any issues. Apologies.