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
{{ message }}
Repository navigation
Can't map user-defined range with subtype StoreType when the subtype type is plugin-provided #688
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)
Not exactly sure, but I suspect it's related to using the preview version of the provider but not the preview version of the plugin (significant changes in this area for 2.2).
obj/Debug/netcoreapp2.1/EFCoreNpgsqlNodaTime.cs(10,12): error CS1729: 'DesignTimeServicesReferenceAttribute' does not contain a constructor that takes 2 arguments
Which I'm guessing is due to an ef version mismatch?
System.TypeLoadException: Could not load type 'Microsoft.EntityFrameworkCore.Infrastructure.IRelationalDbContextOptionsBuilderInfrastructure' from assembly 'Microsoft.EntityFrameworkCore.Relational, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
at Microsoft.EntityFrameworkCore.NpgsqlNodaTimeDbContextOptionsBuilderExtensions.UseNodaTime(NpgsqlDbContextOptionsBuilder optionsBuilder)
at Server.Startup.<>c.b__4_3(NpgsqlDbContextOptionsBuilder opts) in /Users/shoe/Git/graph/src/Startup.cs:line 38
at Microsoft.EntityFrameworkCore.NpgsqlDbContextOptionsExtensions.UseNpgsql(DbContextOptionsBuilder optionsBuilder, String connectionString, Action`1 npgsqlOptionsAction) in C:\projects\npgsql-entityframeworkcore-postgresql\src\EFCore.PG\Extensions\NpgsqlDbContextOptionsExtensions.cs:line 66
Hmm.... Yeah that looks like some type of mismatch is happening, but I haven't seen that particular one before.
Did you run a clean/restore cycle after updating?
If that doesn't work, we'll probably need to see some more code, or even a minimal repo to speculate further.
edit: posted the above before your second response, see below for follow up.
I don't think you need to bring in the EF Core preview, as the proper preview is included by the PostgreSQL provider. Try rolling that back, and doing a full clean/restore/build cycle and report back.
Of 2.2.0-preview1-35029, 2.2.0-preview2-35157 and 2.2.0-preview3-35497 for Microsoft.EntityFrameworkCore the first two yield the DesignTimeServicesReferenceAttribute related error. The last one instead complains about IRelationalDbContextOptionsBuilderInfrastructure which was probably introduced in preview3?
Taking a look at the design time services now. It also looks like we don't have a preview build of the plugin, just a recent CI build in the unstable feed.
So the first level issue is the versions still need to be set to the unstable feed. @Jefffrey Could you try using the CI builds for both and report back?
namespaceEFCore.PG_688{classProgram{staticvoidMain(){using(varctx=newSomeContext()){try{ctx.Database.EnsureCreated();Console.WriteLine(ctx.SomeModel.Count());}finally{ctx.Database.EnsureDeleted();}}}}publicclassSomeModel{publicintId{get;set;}publicNpgsqlRange<LocalTime>Period{get;set;}}publicclassSomeContext:DbContext{publicDbSet<SomeModel>SomeModel{get;set;}protectedoverridevoidOnConfiguring(DbContextOptionsBuilderbuilder)=>builder.UseNpgsql("Host=localhost;Port=5432",
x =>x.UseNodaTime().MapRange<LocalTime>("timerange","time"));protectedoverridevoidOnModelCreating(ModelBuilderbuilder)=>builder.ForNpgsqlHasRange("timerange","time");}}
The surprising piece is this:
protectedoverridevoidOnConfiguring(DbContextOptionsBuilderbuilder)=>builder.UseNpgsql("Host=localhost;Port=5432",
x =>x.UseNodaTime().MapRange<LocalTime>("timerange","time"));
You should be able to omit the "time" parameter, but the type resolution doesn't seem to do the hop from timerange to NpgsqlRange<LocalTime> to the subtype. actually the subtype should be resolved just by the mapping of the CLR LocalTime type to the PostgreSQL time type.
When the subtype is specified explicitly (e.g. "time") the CLR type isn't searched, giving the plugin's TypeMappingSource time to load before the handler is needed.
@roji Do you have a sense of how best we can affect this ordering?
warning NU1603: Server depends on Npgsql.EntityFrameworkCore.PostgreSQL (>= 2.2.0-ci.1110) but Npgsql.EntityFrameworkCore.PostgreSQL 2.2.0-ci.1110 was not found. An approximate best match of Npgsql.EntityFrameworkCore.PostgreSQL 2.2.0-preview1 was resolved.
You'll need to add a nuget.config to your project root with something like this:
System.Exception: Could not map range timerange, no mapping was found for subtype CLR type NodaTime.LocalTime
at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlTypeMappingSource..ctor(TypeMappingSourceDependencies dependencies, RelationalTypeMappingSourceDependencies relationalDependencies, INpgsqlOptions npgsqlOptions) in C:\projects\npgsql-entityframeworkcore-postgresql\src\EFCore.PG\Storage\Internal\NpgsqlTypeMappingSource.cs:line 246
@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.
changed the title [-]New custom range support: Could not load type NpgsqlRangeTypeMapping[/-][+]Can't map user-defined range with subtype StoreType when the subtype type is plugin-provided[/+]on Nov 15, 2018
Activity
austindrenski commentedon Nov 5, 2018
Not exactly sure, but I suspect it's related to using the preview version of the provider but not the preview version of the plugin (significant changes in this area for 2.2).
Try updating your versions and report back:
shoooe commentedon Nov 6, 2018
@austindrenski I then get:
Which I'm guessing is due to an ef version mismatch?
shoooe commentedon Nov 6, 2018
Tried with:
and now I get:
austindrenski commentedon Nov 6, 2018
Hmm.... Yeah that looks like some type of mismatch is happening, but I haven't seen that particular one before.
Did you run a clean/restore cycle after updating?
If that doesn't work, we'll probably need to see some more code, or even a minimal repo to speculate further.
edit: posted the above before your second response, see below for follow up.
I don't think you need to bring in the EF Core preview, as the proper preview is included by the PostgreSQL provider. Try rolling that back, and doing a full clean/restore/build cycle and report back.
shoooe commentedon Nov 6, 2018
Of 2.2.0-preview1-35029, 2.2.0-preview2-35157 and 2.2.0-preview3-35497 for Microsoft.EntityFrameworkCore the first two yield the
DesignTimeServicesReferenceAttributerelated error. The last one instead complains aboutIRelationalDbContextOptionsBuilderInfrastructurewhich was probably introduced in preview3?shoooe commentedon Nov 6, 2018
@austindrenski I run a
dotnet clean && dotnet restoreyes, and nothing changed.I think you can reproduce the issue by creating a new dotnet project and just define a model with a range for
LocalTimefollowing the first post.austindrenski commentedon Nov 6, 2018
I can indeed reproduce this locally with https://github.com/austindrenski/EFCore.PG-688.
Taking a look at the design time services now. It also looks like we don't have a preview build of the plugin, just a recent CI build in the unstable feed.
austindrenski commentedon Nov 6, 2018
So the first level issue is the versions still need to be set to the unstable feed. @Jefffrey Could you try using the CI builds for both and report back?
The second level issue is found in the repo:
The surprising piece is this:
You should be able to omit the
"time"parameter,but the type resolution doesn't seem to do the hop fromactually the subtype should be resolved just by the mapping of the CLRtimerangetoNpgsqlRange<LocalTime>to the subtype.LocalTimetype to the PostgreSQLtimetype.austindrenski commentedon Nov 6, 2018
It looks like the plugin's
TypeMappingSourceisn't loaded beforeMapRange<LocalTime>("timerange")attempts to resolve the subtype's mapping:https://github.com/npgsql/Npgsql.EntityFrameworkCore.PostgreSQL/blob/e7bea847e458f9aa68ff14c663ba0f9f46359537/src/EFCore.PG/Storage/Internal/NpgsqlTypeMappingSource.cs#L244-L252
When the subtype is specified explicitly (e.g.
"time") the CLR type isn't searched, giving the plugin'sTypeMappingSourcetime to load before the handler is needed.@roji Do you have a sense of how best we can affect this ordering?
austindrenski commentedon Nov 6, 2018
@Jefffrey wrote:
You'll need to add a
nuget.configto your project root with something like this:shoooe commentedon Nov 6, 2018
@austindrenski I get:
by having:
austindrenski commentedon Nov 6, 2018
@Jefffrey Yes, that's the exception I referenced above.
roji commentedon Nov 11, 2018
I'll try to take a look at this very soon.
roji commentedon 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
ClrTypeMappingdictionary, 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 additionalFindUserDefinedRangeMapping()which gets called, just likeFindArrayMapping(). LikeFindArrayMapping(), if a mapping is instantiated, we can update NpgsqlTypeMappingSource'sClrTypeMappingandStoreTypeMappingdictionaries so that the next lookup simply finds it viaFindExistingMapping(). Also, when looking for the subtype we definitely should not look atClrTypeMapping, but rather recursively callFindMapping()which would include the plugins (again, exactly likeFindArrayMapping()already does).Are you interested in fixing this? If not I can probably do this quite quickly.
austindrenski commentedon Nov 13, 2018
@roji That sounds good to me. It sounds like you have a specific implementation in mind, so no objections here! Happy to review once submitted.
Fix user-defined range mappings
[-]New custom range support: Could not load type NpgsqlRangeTypeMapping[/-][+]Can't map user-defined range with subtype StoreType when the subtype type is plugin-provided[/+]Fix user-defined range mappings