dotnet/efcore · error · InvalidOperationException
' . ' and ' . ' are both mapped to column ' ' in ' ', but…
Error message
'{entityType1}.{property1}' and '{entityType2}.{property2}' are both mapped to column '{columnName}' in '{table}', but are configured with different scales ('{scale1}' and '{scale2}'). What it means
Two properties sharing a column declare different numeric scales (the second HasPrecision argument, or HasScale). Scale is the number of digits after the decimal point; differing scales on one physical column are irreconcilable, so EF rejects the model.
Solutions
- Set the same scale (second HasPrecision argument, or HasScale) on both properties.
- Choose the larger scale to preserve precision across both usages.
- Remap one property to a distinct column if the scales are genuinely different.
Example fix
// before modelBuilder.Entity<Order>().Property(o => o.Total).HasPrecision(18, 2); modelBuilder.Entity<OrderDiscount>().Property(d => d.Total).HasPrecision(18, 4); // shared column // after modelBuilder.Entity<Order>().Property(o => o.Total).HasPrecision(18, 4); modelBuilder.Entity<OrderDiscount>().Property(d => d.Total).HasPrecision(18, 4);
Defensive patterns
Strategy: validation
Validate before calling
foreach (var (col, props) in sharedColumnGroups)
{
var scales = props.Select(p => p.GetScale(storeObject)).Distinct().ToList();
if (scales.Count > 1)
Console.WriteLine($"Column {col} has conflicting scales: {string.Join(", ", scales)}");
} Try / catch
try { _ = db.Model; } catch (InvalidOperationException ex) when (ex.Message.Contains("different scales")) { // align the scale argument of HasPrecision on both properties } Prevention
- Always set precision and scale together via HasPrecision(p, s) and reuse the same call.
- Use named constants for currency vs percentage scales.
- Smoke-test the model at startup.
When it happens
Trigger: ValidateCompatible() compares property.GetScale(storeObject) vs duplicateProperty.GetScale(storeObject) for a duplicate column and they differ.
Common situations: A rate column shared between owner and owned entity where one was configured for 4 decimal places and the other for 2; currency vs percentage fields that ended up mapped to the same column after refactoring.
Related errors
- ' . ' and ' . ' are both mapped to column ' ' in ' ', but…
- ' . ' and ' . ' are both mapped to column ' ' in ' ', but…
- ' . ' and ' . ' are both mapped to column ' ' in ' ', but…
- ' . ' and ' . ' are both mapped to column ' ' in ' ', but…
- ' . ' and ' . ' are both mapped to column ' ' in ' ', but…
AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11).
Data as JSON: /api/errors/2f94262d4e34b1bb.
Report an issue: GitHub.
Appendix: source
Thrown at src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs:1606
if (currentPrecision != previousPrecision)
{
throw new InvalidOperationException(
RelationalStrings.DuplicateColumnNamePrecisionMismatch(
duplicateProperty.DeclaringType.DisplayName(),
duplicateProperty.Name,
property.DeclaringType.DisplayName(),
property.Name,
columnName,
storeObject.DisplayName(),
currentPrecision,
previousPrecision));
}
var currentScale = property.GetScale(storeObject);
var previousScale = duplicateProperty.GetScale(storeObject);
if (currentScale != previousScale)
{
throw new InvalidOperationException(
RelationalStrings.DuplicateColumnNameScaleMismatch(
duplicateProperty.DeclaringType.DisplayName(),
duplicateProperty.Name,
property.DeclaringType.DisplayName(),
property.Name,
columnName,
storeObject.DisplayName(),
currentScale,
previousScale));
}
if (property.IsConcurrencyToken != duplicateProperty.IsConcurrencyToken)
{
throw new InvalidOperationException(
RelationalStrings.DuplicateColumnNameConcurrencyTokenMismatch(
duplicateProperty.DeclaringType.DisplayName(),
duplicateProperty.Name,
property.DeclaringType.DisplayName(),View on GitHub (pinned to 3a2006ef56)