I'm getting the following error trying to load the results of my Postgres function into a EF entity.
Error:
Microsoft.EntityFrameworkCore.Query: Error: An exception occurred while iterating over the results of a query for context type 'Rainman.Data.RainmanDbContext'.
System.Threading.ThreadAbortException: System error.
at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior)
at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteReader()
at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReader(RelationalCommandParameterObject parameterObject)
at Microsoft.EntityFrameworkCore.Query.Internal.FromSqlQueryingEnumerable`1.Enumerator.InitializeReader(DbContext _, Boolean result)
at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
at Microsoft.EntityFrameworkCore.Query.Internal.FromSqlQueryingEnumerable`1.Enumerator.MoveNext()
While running the following code:
FormattableString query = $"SELECT sortedsetkey as \"SortedSetKey\", keyorder as \"KeyOrder\", value as \"Value\" FROM public.fn_test_lcr_custom({routePlan.DeckApplyCustomer.tg_id}, {routePlan.effective_date});";
Console.WriteLine($"\n\nQUERY:\n{query}\n\n");
IEnumerable <CustomerRoutingCache> tmpList = RainmanDbContext.CustomerRoutingCaches.FromSqlInterpolated(query).AsEnumerable();
This SQL Function Definition for the function being called on the Postgres side (ver 13):
CREATE OR REPLACE FUNCTION public.fn_test_lcr_custom(
p_tg_id text,
p_as_of_date timestamp with time zone)
RETURNS TABLE(SortedSetKey text, KeyOrder int, Value text)
The class that it being translated into is:
public class CustomerRoutingCache
{
[Key]
public string SortedSetKey { get; set; }
public int KeyOrder { get; set; }
public string Value { get; set; }
}
Using .net core 5, npgsql