I'm using current EF 6.0 code - my own local build of EF against the master branch, synced an hour or two ago. I synched just to make sure that the problems I'm seeing weren't already fixed.
I've created an xunit test to show the problems. The fundamental problem is that I'm not able to use these 3 things together:
* A custom DateTime convention (same behavior for both lightweight convention and a convention class)
* A TPT entity type with a base class
* Configuring the DateTime precision (overriding the convention) for a property in the entity.
The code is attached.
The crux of the problem is demonstrated here:
``` C#
internal class TablePerTypeDbContext : DbContext
{
public DbSet<DerivedEntity> Entities { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// Lightweight convention for DateTime properties: Use SQL datetime2 type, default precision 1.
modelBuilder.Properties<DateTime>().Configure(dateTimeConfig =>
{
dateTimeConfig.HasColumnType("datetime2");
dateTimeConfig.HasPrecision(1);
});
// Use table per type
modelBuilder.Entity<DerivedEntity>().Map(m => m.MapInheritedProperties());
// Set precision to 3 for LastModified property (overrides the convention)
// BUG: No combination of uncommenting the following 2 lines works as it should
//modelBuilder.Entity<DerivedEntity>().Property(e => e.LastModified).HasPrecision(3);
//modelBuilder.Entity<BaseEntity>().Property(e => e.LastModified).HasPrecision(3);
}
}
```
EF Behavior varies wildly depending on which of the last 2 lines are uncommented:
1. With both commented out, table dbo.DerivedEntities is created, and LastModified column has precision 1 (expected behavior).
2. With the DerivedEntity line uncommented, InvalidOperationException is thrown: Conflicting configuration settings were specified for property 'LastModified' on type 'Base.DataAccess.UnitTests.BaseEntity': Precision = 3 conflicts with Precision = 1
3. With both lines uncommented, table dbo.BaseEntities is created, and LastModified column has precision 3 (precision is right, but table name is wrong - acts like TPH instead of TPT)
4. With the DerivedEntity line commented out, and BaseEntity line uncommented, the behavior is the same as #3: table dbo.BaseEntities is created, and LastModified column has precision 3 (precision is right, but table name is wrong - acts like TPH instead of TPT)
I've created an xunit test to show the problems. The fundamental problem is that I'm not able to use these 3 things together:
* A custom DateTime convention (same behavior for both lightweight convention and a convention class)
* A TPT entity type with a base class
* Configuring the DateTime precision (overriding the convention) for a property in the entity.
The code is attached.
The crux of the problem is demonstrated here:
``` C#
internal class TablePerTypeDbContext : DbContext
{
public DbSet<DerivedEntity> Entities { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// Lightweight convention for DateTime properties: Use SQL datetime2 type, default precision 1.
modelBuilder.Properties<DateTime>().Configure(dateTimeConfig =>
{
dateTimeConfig.HasColumnType("datetime2");
dateTimeConfig.HasPrecision(1);
});
// Use table per type
modelBuilder.Entity<DerivedEntity>().Map(m => m.MapInheritedProperties());
// Set precision to 3 for LastModified property (overrides the convention)
// BUG: No combination of uncommenting the following 2 lines works as it should
//modelBuilder.Entity<DerivedEntity>().Property(e => e.LastModified).HasPrecision(3);
//modelBuilder.Entity<BaseEntity>().Property(e => e.LastModified).HasPrecision(3);
}
}
```
EF Behavior varies wildly depending on which of the last 2 lines are uncommented:
1. With both commented out, table dbo.DerivedEntities is created, and LastModified column has precision 1 (expected behavior).
2. With the DerivedEntity line uncommented, InvalidOperationException is thrown: Conflicting configuration settings were specified for property 'LastModified' on type 'Base.DataAccess.UnitTests.BaseEntity': Precision = 3 conflicts with Precision = 1
3. With both lines uncommented, table dbo.BaseEntities is created, and LastModified column has precision 3 (precision is right, but table name is wrong - acts like TPH instead of TPT)
4. With the DerivedEntity line commented out, and BaseEntity line uncommented, the behavior is the same as #3: table dbo.BaseEntities is created, and LastModified column has precision 3 (precision is right, but table name is wrong - acts like TPH instead of TPT)