Description
Bug Description
I am using a single BaseRepository instance across multiple threads. As long as I make a "prewarm" single-threaded call, all other parallel queries work without issue. However, without a "prewarm," I run into random errors. The errors occur seemingly at random, such as DateOnly cannot being converted to DateTime, DbNull versus non-DbNull, and so on. It seems there may be a problem while initializing the mapper (I am not using any cache or mapper of my own, I simply use the BaseRepository without any arguments other than the connection string).
I have called PostgreSqlBootstrap.Initialize before, and I ensure that it is called only once.
Question: What is the correct way to handle concurrent queries?
Exception Message:
System.InvalidOperationException: Compiler.DataReader.IsDbNull.FalseExpression: Failed to convert the value expression into its destination .NET CLR Type 'System.Collections.Generic.List`1[[Bar.Client.NsPriceListColumn, Foo.DataSource.Bar.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]'. PropertyInfo: Columns (System.Collections.Generic.List`1[Bar.Client.NsPriceListColumn]), DeclaringType: Bar.Client.NsPriceList
---> System.InvalidOperationException: No coercion operator is defined between types 'System.String' and 'System.Collections.Generic.List`1[Bar.Client.NsPriceListColumn]'.
at System.Linq.Expressions.Expression.GetUserDefinedCoercionOrThrow(ExpressionType coercionType, Expression expression, Type convertToType)
at RepoDb.Reflection.Compiler.ConvertExpressionToTypeExpression(Expression expression, Type toType)
at RepoDb.Reflection.Compiler.GetClassPropertyParameterInfoIsDbNullFalseValueExpression(ParameterExpression readerParameterExpression, ClassPropertyParameterInfo classPropertyParameterInfo, DataReaderField readerField)
--- End of inner exception stack trace ---
at RepoDb.Reflection.Compiler.GetClassPropertyParameterInfoIsDbNullFalseValueExpression(ParameterExpression readerParameterExpression, ClassPropertyParameterInfo classPropertyParameterInfo, DataReaderField readerField)
at RepoDb.Reflection.Compiler.GetClassPropertyParameterInfoValueExpression(ParameterExpression readerParameterExpression, ClassPropertyParameterInfo classPropertyParameterInfo, DataReaderField readerField)
at RepoDb.Reflection.Compiler.GetMemberBindingsForDataEntity[TResult](ParameterExpression readerParameterExpression, IEnumerable`1 readerFields, IDbSetting dbSetting)
at RepoDb.Reflection.Compiler.CompileDataReaderToDataEntity[TResult](DbDataReader reader, IEnumerable`1 dbFields, IDbSetting dbSetting)
at RepoDb.Reflection.Compiler.CompileDataReaderToType[TResult](DbDataReader reader, IEnumerable`1 dbFields, IDbSetting dbSetting)
at RepoDb.Reflection.FunctionFactory.CompileDataReaderToType[TResult](DbDataReader reader, IEnumerable`1 dbFields, IDbSetting dbSetting)
at RepoDb.FunctionCache.DataReaderToTypeCache`1.Get(DbDataReader reader, IEnumerable`1 dbFields, IDbSetting dbSetting)
at RepoDb.FunctionCache.GetDataReaderToTypeCompiledFunction[TResult](DbDataReader reader, IEnumerable`1 dbFields, IDbSetting dbSetting)
at RepoDb.Reflection.DataReader.ToEnumerable[TResult](DbDataReader reader, IEnumerable`1 dbFields, IDbSetting dbSetting)+MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at RepoDb.Extensions.EnumerableExtension.AsList[T](IEnumerable`1 value)
at RepoDb.DbConnectionExtension.ExecuteQueryInternalForType[TResult](IDbConnection connection, String commandText, Object param, Nullable`1 commandType, String cacheKey, Nullable`1 cacheItemExpiration, String traceKey, Nullable`1 commandTimeout, IDbTransaction transaction, ICache cache, ITrace trace, String tableName, Boolean skipCommandArrayParametersCheck)
at RepoDb.DbConnectionExtension.ExecuteQueryInternal[TResult](IDbConnection connection, String commandText, Object param, Nullable`1 commandType, String cacheKey, Nullable`1 cacheItemExpiration, String traceKey, Nullable`1 commandTimeout, IDbTransaction transaction, ICache cache, ITrace trace, String tableName, Boolean skipCommandArrayParametersCheck)
at RepoDb.DbConnectionExtension.QueryInternalBase[TEntity](IDbConnection connection, String tableName, QueryGroup where, IEnumerable`1 fields, IEnumerable`1 orderBy, Nullable`1 top, String hints, String cacheKey, Nullable`1 cacheItemExpiration, Nullable`1 commandTimeout, String traceKey, IDbTransaction transaction, ICache cache, ITrace trace, IStatementBuilder statementBuilder)
at RepoDb.DbConnectionExtension.QueryInternal[TEntity](IDbConnection connection, String tableName, QueryGroup where, IEnumerable`1 fields, IEnumerable`1 orderBy, Nullable`1 top, String hints, String cacheKey, Nullable`1 cacheItemExpiration, Nullable`1 commandTimeout, String traceKey, IDbTransaction transaction, ICache cache, ITrace trace, IStatementBuilder statementBuilder)
at RepoDb.DbConnectionExtension.Query[TEntity,TWhat](IDbConnection connection, TWhat what, IEnumerable`1 fields, IEnumerable`1 orderBy, Nullable`1 top, String hints, String cacheKey, Nullable`1 cacheItemExpiration, Nullable`1 commandTimeout, String traceKey, IDbTransaction transaction, ICache cache, ITrace trace, IStatementBuilder statementBuilder)
at RepoDb.DbRepository`1.Query[TEntity,TWhat](TWhat what, IEnumerable`1 fields, IEnumerable`1 orderBy, Nullable`1 top, String hints, String traceKey, String cacheKey, IDbTransaction transaction)
at RepoDb.BaseRepository`2.Query[TWhat](TWhat what, IEnumerable`1 fields, IEnumerable`1 orderBy, Nullable`1 top, String hints, String cacheKey, String traceKey, IDbTransaction transaction)
at Foo.DataSource.Bar.NsRepository`1.GetById(Int32 id) in C:\Users\user\projects\Foo\src\Foo.DataSource.Bar\NsRepository.cs:line 124
at Foo.DataSource.Bar.NsDataSourceObjectConverter`2.<>c__DisplayClass1_0.<ConvertedList>b__0(Int32 id) in C:\Users\user\projects\Foo\src\Foo.DataSource.Bar\NsDataSourceObjectConverter.cs:line 29
at System.Threading.Tasks.Parallel.<>c__DisplayClass32_0`2.<ForEachWorker>b__0(Int32 i)
at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
Library Version:
Example: RepoDb v1.13 and RepoDb.Postgres v1.13