question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't map user-defined range with subtype StoreType when the subtype type is plugin-provided

See original GitHub issue

I’ve attempted to use the new custom range type support with LocalTime (from NodaTime).

So I’ve set it up with:

            services.AddDbContext<MainContext>(options => 
                options.UseNpgsql(
                    Configuration.GetConnectionString("MainContext"),
                    opts => 
                    {
                        opts.UseNodaTime();
                        opts.MapRange<LocalTime>("timerange");
                    }));

and:

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.ForNpgsqlHasRange("timerange", "time");
            // ...
        }

Then in one of my model classes I’ve put:

public NpgsqlRange<LocalTime> Period { get; set; }

Then I ran:

dotnet ef migrations add Initial

and I get:

System.TypeLoadException: Could not load type 'Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.Mapping.NpgsqlRangeTypeMapping`1' from assembly 'Npgsql.EntityFrameworkCore.PostgreSQL, Version=2.2.0.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7'.
   at Npgsql.EntityFrameworkCore.PostgreSQL.NodaTime.NodaTimePlugin..ctor()
   at Microsoft.EntityFrameworkCore.NodaTimeDbContextOptionsExtensions.UseNodaTime(NpgsqlDbContextOptionsBuilder optionsBuilder) in /home/roji/projects/EFCore.PG/src/EFCore.PG.NodaTime/NodaTimeDbContextOptionsExtensions.cs:line 20
   at Server.Startup.<>c.<ConfigureServices>b__4_2(NpgsqlDbContextOptionsBuilder opts)

These are the versions I’m using:

    <PackageReference Include="NodaTime" Version="2.3.0" />
    <PackageReference Include="Npgsql" Version="4.0.3" />
    <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.2.0-preview1" />
    <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.NodaTime" Version="2.1.1" />

What am I doing wrong?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:15 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
rojicommented, Nov 13, 2018

@austindrenski OK, I took a look and your analysis seems correct… The user-defined range mapping setup process involves looking at NpgsqlTypeMappingSource’s ClrTypeMapping dictionary, but that dictionary only includes the built-in mappings, and not the plugins.

I think the right way would be to move the user-defined range logic out of the constructor and into FindMapping(), probably by adding an additional FindUserDefinedRangeMapping() which gets called, just like FindArrayMapping(). Like FindArrayMapping(), if a mapping is instantiated, we can update NpgsqlTypeMappingSource’s ClrTypeMapping and StoreTypeMapping dictionaries so that the next lookup simply finds it via FindExistingMapping(). Also, when looking for the subtype we definitely should not look at ClrTypeMapping, but rather recursively call FindMapping() which would include the plugins (again, exactly like FindArrayMapping() already does).

Are you interested in fixing this? If not I can probably do this quite quickly.

1reaction
austindrenskicommented, Nov 6, 2018

@Jefffrey Yes, that’s the exception I referenced above.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuring AMQ Streams on OpenShift
Kafka and ZooKeeper storage types. 2.1.3.1. ... Map Red Hat Single Sign-On Authorization Services to the Kafka authorization model. 5.5.3.3.
Read more >
Configuring Strimzi (0.33.2)
Strimzi provides a way to run an Apache Kafka cluster on Kubernetes in various deployment configurations.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found