-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Description
Include your code
When updating Microsoft.EntityFrameworkCore.SqlServer from 6.0.11 to 7.0.0 I receive a new error. I checked the breaking changes and full release notes and I can't see anything that should impact this.
I have four entities types mapped to the same database column. Column is named "LowVoltageThreshold" and is float nullable in the database.
Three of these entities map directly to a double? property:
public double? Threshold { get; set; }
public void Configure(EntityTypeBuilder<BearingChangedAlarmSetting> entity)
{
entity.HasBaseType<AlarmSetting>();
entity.Property(e => e.Threshold).HasColumnName("LowVoltageThreshold");
}
The other map to utility class containing a float? property, so I use a converter to convert from double? to float?:
public class DistanceUnit
{
public float? Metres { get; set; }
[...]
}
public DistanceUnit Threshold { get; set; }
public void Configure(EntityTypeBuilder<RouteLengthChangedAlarmSetting> entity)
{
entity.HasBaseType<AlarmSetting>();
entity.Property(e => e.Threshold)
.HasColumnName("LowVoltageThreshold")
.HasConversion(e => (double?)e.Metres, e => new DistanceUnit { Metres = (float?)e });
}
When looking at the signature returned by HasConversion it indeed have the nullable "?" in the type:
So where does that "double" without the nullable comes from in the compatibility validation? And why did this behavior change in v7?
Include stack traces
Include the full exception message and stack trace for any exception you encounter.
System.InvalidOperationException: 'BearingChangedAlarmSetting.Threshold' and 'RouteLengthChangedAlarmSetting.Threshold' are both mapped to column 'LowVoltageThreshold' in 'AlarmSettings', but are configured to use differing provider types ('double' and 'double?').
at Microsoft.EntityFrameworkCore.Infrastructure.RelationalModelValidator.ValidateCompatible(IProperty property, IProperty duplicateProperty, String columnName, StoreObjectIdentifier& storeObject, IDiagnosticsLogger`1 logger)
at Microsoft.EntityFrameworkCore.SqlServer.Infrastructure.Internal.SqlServerModelValidator.ValidateCompatible(IProperty property, IProperty duplicateProperty, String columnName, StoreObjectIdentifier& storeObject, IDiagnosticsLogger`1 logger)
at Microsoft.EntityFrameworkCore.Infrastructure.RelationalModelValidator.ValidateSharedColumnsCompatibility(IReadOnlyList`1 mappedTypes, StoreObjectIdentifier& storeObject, IDiagnosticsLogger`1 logger)
at Microsoft.EntityFrameworkCore.SqlServer.Infrastructure.Internal.SqlServerModelValidator.ValidateSharedColumnsCompatibility(IReadOnlyList`1 mappedTypes, StoreObjectIdentifier& storeObject, IDiagnosticsLogger`1 logger)
at Microsoft.EntityFrameworkCore.Infrastructure.RelationalModelValidator.ValidateSharedTableCompatibility(IModel model, IDiagnosticsLogger`1 logger)
at Microsoft.EntityFrameworkCore.Infrastructure.RelationalModelValidator.Validate(IModel model, IDiagnosticsLogger`1 logger)
at Microsoft.EntityFrameworkCore.SqlServer.Infrastructure.Internal.SqlServerModelValidator.Validate(IModel model, IDiagnosticsLogger`1 logger)
at Microsoft.EntityFrameworkCore.Infrastructure.ModelRuntimeInitializer.Initialize(IModel model, Boolean designTime, IDiagnosticsLogger`1 validationLogger)
at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.GetModel(DbContext context, ModelCreationDependencies modelCreationDependencies, Boolean designTime)
at Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel(Boolean designTime)
at Microsoft.EntityFrameworkCore.Internal.DbContextServices.get_Model()
Include provider and version information
EF Core version: 7.0.0
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 6.0