Closed
Description
Simple test case throws exception
// model
public class Test
{
public int Id { get; set; }
public NpgsqlRange<DateTime> Valid { get; set; }
}
// dbcontext configuration
public virtual DbSet<App.Test> Tests { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Test>(entity =>
{
entity.ToTable("test", "app");
entity.HasKey(e => e.Id);
entity.Property(e => e.Id).HasColumnName("id");
entity.Property(e => e.Valid).HasColumnName("valid");
});
// migration
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.EnsureSchema(
name: "app");
migrationBuilder.CreateTable(
name: "test",
schema: "app",
columns: table => new
{
Id = table.Column<int>(nullable: false),
Valid = table.Column<NpgsqlRange<DateTime>>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("test_pk", x => new { x.Id});
});
}
// create new entity
var options = new DbContextOptionsBuilder<OptiroContext>()
.UseNpgsql(_connectionString, ob => ob.UseNodaTime().UseNetTopologySuite())
.UseLoggerFactory(Global.ConsoleLoggerFactory).Options;
using (var context = new OptiroContext(options))
{
DateTime validFrom = new DateTime(2018, 09, 21, 0,0,0);
DateTime validTo = DateTime.MaxValue;
context.Tests.Add(new Test
{
Valid = new NpgsqlRange<DateTime>(validFrom, validTo)
});
context.SaveChanges();
}
stack trace
Microsoft.EntityFrameworkCore.DbUpdateException : An error occurred while updating the entries. See the inner exception for details.
---- System.InvalidCastException : Can't write CLR type NpgsqlTypes.NpgsqlRange`1[System.DateTime] with handler type RangeHandler`1
at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.Execute(IRelationalConnection connection)
at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(DbContext _, ValueTuple`2 parameters)
at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded) in C:\projects\npgsql-entityframeworkcore-postgresql\src\EFCore.PG\Storage\Internal\NpgsqlExecutionStrategy.cs:line 51
at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(IEnumerable`1 commandBatches, IRelationalConnection connection)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(IReadOnlyList`1 entriesToSave)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(Boolean acceptAllChangesOnSuccess)
at Microsoft.EntityFrameworkCore.DbContext.SaveChanges(Boolean acceptAllChangesOnSuccess)
at Optiro.Data.OptiroContext.SaveChanges(Boolean acceptAllChangesOnSuccess) in C:\PROJECTS\test\dbContext.cs:line 3145
at Optiro.Data.Tests.AuditTest.Test1() in C:\PROJECTS\test\Test.cs:line 80
package refererences
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.3" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="2.1.1" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.1.2" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.Design" Version="1.1.1" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.NetTopologySuite" Version="2.1.1" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.NodaTime" Version="2.1.1" />
<PackageReference Include="Npgsql.Json.NET" Version="1.0.0" />
</ItemGroup>
Metadata
Metadata
Assignees
Labels
No labels
Activity
austindrenski commentedon Sep 21, 2018
By design, the BCL date/time types are not supported when the NodaTime plugin is configured.
I'm going to close this for now, but please feel free to post-back if you have further questions.
roji commentedon Sep 23, 2018
@austindrenski FYI I completely removed the
invalidtag... We used to have this in Npgsql too, but it seems to make more sense to just leave invalid issues untagged. So any issue that's closed and untagged implicitly did not mature into a feature/bug/whatever. Is that OK with you?austindrenski commentedon Sep 23, 2018
@roji That totally works for me. I was just trying follow previous patterns, but thinking about it now, marking a well-intentioned question as invalid does seem a bit.... unwelcoming?
So that's OK with me!
baurzhan commentedon Sep 27, 2018
Can you add notice about this restriction in NodaTime Type Plugin documentation page?