-
Notifications
You must be signed in to change notification settings - Fork 228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't write arrays of user-defined ranges #3137
Comments
@roji this might be related to https://github.com/npgsql/npgsql/pull/5123/files#r1325747341 If so setting the actual datatypename of the range on the param should solve it. EDIT: traced the regstration to
is not supported for parameters having NpgsqlDbType kind of error. That only happens if it was set somehow.
|
I notice your entity has the following attribute
Specifically |
@NinoFloris I'm sorry. The issue is actually related to array of ranges
Usual
Is it possible to use array(NpgsqlRange[]) now in 8.02 version? |
@NinoFloris going over some untriaged issues - am assigning to you as you've already looked into it and there's a good chance this is an Npgsql-level problem. EF minimal reproawait using var context = new BlogContext();
await context.Database.EnsureDeletedAsync();
await context.Database.EnsureCreatedAsync();
await using (var connection = await BlogContext.DataSource.OpenConnectionAsync())
{
await connection.ReloadTypesAsync();
}
context.Blogs.Add(
new()
{
AllowedTimeRanges =
[
new(TimeSpan.FromHours(1), TimeSpan.FromHours(2)),
new(TimeSpan.FromHours(4), TimeSpan.FromHours(6))
]
});
await context.SaveChangesAsync();
public class BlogContext : DbContext
{
public static readonly NpgsqlDataSource DataSource;
static BlogContext()
{
var dataSourceBuilder = new NpgsqlDataSourceBuilder("Host=localhost;Username=test;Password=test");
dataSourceBuilder.EnableUnmappedTypes();
DataSource = dataSourceBuilder.Build();
}
public DbSet<Blog> Blogs { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseNpgsql(DataSource, o => o.MapRange<TimeSpan>("timerange", subtypeName: "time without time zone"))
.LogTo(Console.WriteLine, LogLevel.Information)
.EnableSensitiveDataLogging();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasPostgresRange(name: "timerange", subtype: "time without time zone");
}}
public class Blog
{
public int Id { get; set; }
[Column(TypeName = "timerange[]")]
public NpgsqlRange<TimeSpan>[] AllowedTimeRanges { get; set; }
} |
Quickly ran the repro in the Npgsql project, EF Pg ends up setting As NpgsqlDbType takes precedence we don't know what I expect that when we stop setting NpgsqlDbType this way the issue will be resolved. This with some composition of the array mapping will cause it: efcore.pg/src/EFCore.PG/Storage/Internal/Mapping/NpgsqlRangeTypeMapping.cs Lines 70 to 78 in e4375aa
|
EF sets both NpgsqlDbType and DataTypeName? Weird... |
Thanks for looking @NinoFloris, yeah, this was a result of some complexity around using NpgsqlDbType vs. DataTypeName in addition to arrays. The whole area probably needs a bit of cleanup at some point, but submitted #3342 in the meantime as a targeted fix. |
Steps to reproduce
Hi, after Npgsql.EntityFrameworkCore.PostgreSQL update from to 7.0.4 to 8.0.2. We have started to receive an exception when saving into db.
InvalidCastException: Writing values of 'NpgsqlTypes.NpgsqlRange`1[[System.TimeSpan, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]][]' is not supported for parameters having NpgsqlDbType '-2147483608'.
Registration example
The timerange it's a custom timerange type:
How can we solve this error? Before update it was working,
The text was updated successfully, but these errors were encountered: