Skip to content

Support mapping PostgreSQL arrays to List<T> #392

Closed

Description

@MarcosAndre

Hi,
I got an exception when I'm trying to create a new migration.

Version: 2.1.0 RC1 version

Error:

`System.ArgumentNullException: Value cannot be null.
   at System.RuntimeType.MakeGenericType(Type[] instantiation)
   at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.Mapping.NpgsqlArrayTypeMapping.CreateComparer(RelationalTypeMapping elementMapping, Type arrayType) in /home/roji/projects/EFCore.PG/src/EFCore.PG/Storage/Internal/Mapping/NpgsqlArrayTypeMapping.cs:line 99
   at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.Mapping.NpgsqlArrayTypeMapping..ctor(String storeType, RelationalTypeMapping elementMapping, Type arrayType) in /home/roji/projects/EFCore.PG/src/EFCore.PG/Storage/Internal/Mapping/NpgsqlArrayTypeMapping.cs:line 53
   at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlTypeMappingSource.FindArrayMapping(RelationalTypeMappingInfo mappingInfo) in /home/roji/projects/EFCore.PG/src/EFCore.PG/Storage/InternalNpgsqlTypeMappingSource.cs:line 391
   at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlTypeMappingSource.FindMapping(RelationalTypeMappingInfo& mappingInfo) in /home/roji/projects/EFCore.PG/src/EFCore.PG/Storage/Internal/NpgsqlTypeMappingSource.cs:line 323
   at Microsoft.EntityFrameworkCore.Storage.RelationalTypeMappingSource.<FindMappingWithConversion>b__7_0(ValueTuple`3 k)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at Microsoft.EntityFrameworkCore.Storage.RelationalTypeMappingSource.FindMappingWithConversion(RelationalTypeMappingInfo& mappingInfo, IReadOnlyList`1 principals)
   at Microsoft.EntityFrameworkCore.Storage.RelationalTypeMappingSource.FindMapping(MemberInfo member)
   at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.PropertyDiscoveryConvention.IsCandidatePrimitiveProperty(PropertyInfo propertyInfo)
   at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.PropertyDiscoveryConvention.Apply(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.PropertyDiscoveryConvention.Apply(InternalEntityTypeBuilder entityTypeBuilder, EntityType oldBaseType)
   at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ImmediateConventionScope.OnBaseEntityTypeChanged(InternalEntityTypeBuilder entityTypeBuilder, EntityType previousBaseType)
   at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.RunVisitor.VisitOnBaseEntityTypeChanged(OnBaseEntityTypeChangedNode node)
   at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ConventionVisitor.VisitConventionScope(ConventionScope node)
   at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ConventionBatch.Run()
   at Microsoft.EntityFrameworkCore.Metadata.Internal.InternalEntityTypeBuilder.HasBaseType(EntityType baseEntityType, ConfigurationSource configurationSource)
   at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ImmediateConventionScope.OnEntityTypeAdded(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.EntityFrameworkCore.Metadata.Internal.Model.AddEntityType(EntityType entityType)
   at Microsoft.EntityFrameworkCore.Metadata.Internal.InternalModelBuilder.Entity(TypeIdentity& type, ConfigurationSource configurationSource, Boolean throwOnQuery)
   at Microsoft.EntityFrameworkCore.Metadata.Internal.InternalModelBuilder.Entity(Type type, ConfigurationSource configurationSource, Boolean throwOnQuery)
   at Microsoft.EntityFrameworkCore.ModelBuilder.Entity(Type type)
   at Microsoft.EntityFrameworkCore.Infrastructure.ModelCustomizer.FindSets(ModelBuilder modelBuilder, DbContext context)
   at Microsoft.EntityFrameworkCore.Infrastructure.RelationalModelCustomizer.FindSets(ModelBuilder modelBuilder, DbContext context)
   at Microsoft.EntityFrameworkCore.Infrastructure.RelationalModelCustomizer.Customize(ModelBuilder modelBuilder, DbContext context)
   at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.CreateModel(DbContext context, IConventionSetBuilder conventionSetBuilder, IModelValidator validator)
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel()
   at Microsoft.EntityFrameworkCore.Internal.DbContextServices.get_Model()
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, 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_InternalServiceProvider()
   at Microsoft.EntityFrameworkCore.Internal.InternalAccessorExtensions.GetService[TService](IInfrastructure`1 accessor)
   at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(Func`1 factory)
   at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(String contextType)
   at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)`

I think this is related to the commit: 2d0e595

Best regards,
Marcos André

Activity

  1. roji commented on May 9, 2018

    @roji
    Member

    Any chance you can post the relevant parts of your model so I know what triggers this?

  2. MarcosAndre commented on May 9, 2018

    @MarcosAndre
    Author

    I can't, sorry. I have the new value converts, it helps?

  3. changed the title [-]CreateMigration throws ArgumentNullException at NgsqlArrayTypeMapping in the 2.1.0 RC1 version[/-] [+]List<T> triggers exception while creating migration in 2.1.0-rc1[/+] on May 9, 2018
  4. added this to the 2.1.0 milestone on May 9, 2018
  5. self-assigned this
    on May 9, 2018
  6. roji commented on May 9, 2018

    @roji
    Member

    OK, I think I figured it out - you probably have a List<T> of something somewhere in your model, this triggers the error for me. For the moment, change it to an array T[] which should work, I'll look into it.

  7. MarcosAndre commented on May 9, 2018

    @MarcosAndre
    Author

    Yes I have that.

    Thank you ;)

    Cheers!

  8. changed the title [-]List<T> triggers exception while creating migration in 2.1.0-rc1[/-] [+]Support mapping PostgreSQL arrays to List<T>[/+] on May 9, 2018
  9. gary-holland commented on May 11, 2018

    @gary-holland

    HI Roji. Just a quick note, I don't have List, I have ICollection which I suspect is the cause of the issue for me. Hopefully you're fix will cover this also.

    Thanks
    Cheers,

  10. roji commented on May 11, 2018

    @roji
    Member

    Mapping a PostgreSQL array type to an ICollection isn't supported - only array or list. Note that I'm referring to the Npgsql-specific mapping of arrays of primitive types (array of int, array of string) to a single column in PostgreSQL. Otherwise EF Core handles mapping collections of entities as relations, i.e. via a foreign key to another table.

    You may want to take a look at your model again to understand where this is coming from, and possibly post part of it (or all of it) here.

  11. added a commit that references this issue on May 13, 2018
    8f3bae4
  12. added theissue type on Jun 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions