You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I tried mapping user defined functions to methods when an ArgumentExeption was thrown. My functions return explicitly the void type. Also I didn't found any example with the void type.
Previously I had them as Npgsql commands. I'll be using EF SQL querys for now.
Maybe I'm overcomplicating this. I wish to know if this was intended to work or there is another sane way to do it.
User defined function (postgres):
CREATEFUNCTIONmyschema.updatedeviceid(codcharacter integer, newdeviceid text) RETURNS void
LANGUAGE plpgsql
AS $$
...
$$;
CREATEFUNCTIONmyschema.updatelocation(deviceid text, latitude double precision, longitude double precision) RETURNS void
LANGUAGE plpgsql
AS $$
...
$$;
Code:
using Microsoft.EntityFrameworkCore;namespace api.Data
{publicpartialclassPostgresContext:DbContext{partialvoidOnModelCreatingPartial(ModelBuildermodelBuilder){
modelBuilder.HasDbFunction(typeof(PostgresContext).GetMethod(nameof(
UpdateDeviceId),new[]{typeof(int),typeof(string)})).HasName("updateDeviceID");
modelBuilder.HasDbFunction(typeof(PostgresContext).GetMethod(nameof(
UpdateLocation),new[]{typeof(string),typeof(double),typeof(double)})).HasName("updateLocation");}publicstaticvoidUpdateDeviceId(intcodCharacter,stringdeviceId)=>thrownew NotImplementedException();publicstaticvoidUpdateLocation(stringdeviceId,doublelatitude,doublelongitude)=>thrownew NotImplementedException();}}
Stack trace:
System.ArgumentException
HResult=0x80070057
Message=The DbFunction 'UpdateDeviceId' has an invalid return type 'void'. Ensure that the return type can be mapped by the current provider.
Source=Microsoft.EntityFrameworkCore.Relational
StackTrace:
at Microsoft.EntityFrameworkCore.Metadata.Internal.DbFunction..ctor(String name, Type returnType, IEnumerable`1 parameters, IMutableModel model, ConfigurationSource configurationSource)
at Microsoft.EntityFrameworkCore.Metadata.Internal.DbFunction..ctor(MethodInfo methodInfo, IMutableModel model, ConfigurationSource configurationSource)
at Microsoft.EntityFrameworkCore.Metadata.Internal.DbFunction.AddDbFunction(IMutableModel model, MethodInfo methodInfo, ConfigurationSource configurationSource)
at Microsoft.EntityFrameworkCore.RelationalModelExtensions.AddDbFunction(IMutableModel model, MethodInfo methodInfo)
at Microsoft.EntityFrameworkCore.RelationalModelBuilderExtensions.HasDbFunction(ModelBuilder modelBuilder, MethodInfo methodInfo)
at catchflydbapi.Data.PostgresContext.OnModelCreatingPartial(ModelBuilder modelBuilder) in E:\Two\projects\catchfly-dbapi\Data\PostgresContext.cs:line 8
at catchflydbapi.Data.PostgresContext.OnModelCreating(ModelBuilder modelBuilder) in E:\Two\projects\catchfly-dbapi\Autogenerated\Data\PostgresContext.cs:line 83
at Microsoft.EntityFrameworkCore.Infrastructure.ModelCustomizer.Customize(ModelBuilder modelBuilder, DbContext context)
at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.CreateModel(DbContext context, IConventionSetBuilder conventionSetBuilder, ModelDependencies modelDependencies)
at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.GetModel(DbContext context, ModelCreationDependencies modelCreationDependencies, Boolean designTime)
at Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel(Boolean designTime)
at Microsoft.EntityFrameworkCore.Internal.DbContextServices.get_Model()
at Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder.<>c.<TryAddCoreServices>b__8_4(IServiceProvider p)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite callSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite callSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite callSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite callSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite callSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite callSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass2_0.<RealizeService>b__0(ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
at Microsoft.EntityFrameworkCore.DbContext.get_DbContextDependencies()
at Microsoft.EntityFrameworkCore.DbContext.get_ContextServices()
at Microsoft.EntityFrameworkCore.DbContext.get_Model()
at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.get_EntityType()
at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.CheckState()
at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.get_EntityQueryable()
at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.System.Collections.Generic.IAsyncEnumerable<TEntity>.GetAsyncEnumerator(CancellationToken cancellationToken)
at System.Runtime.CompilerServices.ConfiguredCancelableAsyncEnumerable`1.GetAsyncEnumerator()
at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.<ToListAsync>d__67`1.MoveNext()
Include provider and version information
EF Core version: 8.0.4
Database provider: Npgsql.EntityFrameworkCore.PostgreSQL (Version 8.0.2)
Target framework: .NET 8.0
Operating system: Windows 10
IDE: Visual Studio 2022 17.9.6
The text was updated successfully, but these errors were encountered:
I tried mapping user defined functions to methods when an ArgumentExeption was thrown. My functions return explicitly the void type. Also I didn't found any example with the void type.
Previously I had them as Npgsql commands. I'll be using EF SQL querys for now.
Maybe I'm overcomplicating this. I wish to know if this was intended to work or there is another sane way to do it.
User defined function (postgres):
Code:
Stack trace:
Include provider and version information
EF Core version: 8.0.4
Database provider: Npgsql.EntityFrameworkCore.PostgreSQL (Version 8.0.2)
Target framework: .NET 8.0
Operating system: Windows 10
IDE: Visual Studio 2022 17.9.6
The text was updated successfully, but these errors were encountered: