dotnet/efcore · error · InvalidOperationException
'{entityType1}.{property1}' and '{entityType2}.{property2}'
Error message
'{entityType1}.{property1}' and '{entityType2}.{property2}' are both mapped to column '{columnName}' in '{table}', but are configured to use different computed values ('{value1}' and '{value2}'). What it means
Two properties mapped to the same column specify different computed-column SQL expressions (GetComputedColumnSql), compared case-insensitively. A physical computed column can only have one definition, so EF Core aborts finalization. Thrown from ValidateCompatible.
Source
Thrown at src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs:1676
|| (duplicateProperty.IsIndex() && duplicateProperty.GetContainingIndexes().Any(i => i.IsUnique))))
{
throw new InvalidOperationException(
RelationalStrings.DuplicateColumnNameProviderTypeMismatch(
duplicateProperty.DeclaringType.DisplayName(),
duplicateProperty.Name,
property.DeclaringType.DisplayName(),
property.Name,
columnName,
storeObject.DisplayName(),
previousProviderType.ShortDisplayName(),
currentProviderType.ShortDisplayName()));
}
var currentComputedColumnSql = property.GetComputedColumnSql(storeObject) ?? "";
var previousComputedColumnSql = duplicateProperty.GetComputedColumnSql(storeObject) ?? "";
if (!currentComputedColumnSql.Equals(previousComputedColumnSql, StringComparison.OrdinalIgnoreCase))
{
throw new InvalidOperationException(
RelationalStrings.DuplicateColumnNameComputedSqlMismatch(
duplicateProperty.DeclaringType.DisplayName(),
duplicateProperty.Name,
property.DeclaringType.DisplayName(),
property.Name,
columnName,
storeObject.DisplayName(),
previousComputedColumnSql,
currentComputedColumnSql));
}
var currentStored = property.GetIsStored(storeObject);
var previousStored = duplicateProperty.GetIsStored(storeObject);
if (currentStored != previousStored)
{
throw new InvalidOperationException(
RelationalStrings.DuplicateColumnNameIsStoredMismatch(
duplicateProperty.DeclaringType.DisplayName(),View on GitHub (pinned to dbf9771522)
Solutions
- Use identical computed-column SQL on both properties (the validator normalizes case but not whitespace).
- If the formula is intentionally different, rename one column with HasColumnName.
- Remove HasComputedColumnSql from one side and let the other define it (or remove from both if not needed).
Example fix
// before
modelBuilder.Entity<Student>().Property(s => s.Total).HasComputedColumnSql("[Score] + [Bonus]");
modelBuilder.Entity<Teacher>().Property(t => t.Total).HasComputedColumnSql("[Salary] + [Bonus]");
// after
modelBuilder.Entity<Student>().Property(s => s.Total).HasComputedColumnSql("[Score] + [Bonus]");
modelBuilder.Entity<Teacher>().Property(t => t.Total).HasColumnName("TeacherTotal"); Defensive patterns
Strategy: validation
Validate before calling
using (var ctx = new MyContext()) { ctx.Model.ToDebugString(); }
var a = ctx.Model.FindEntityType(typeof(Student))!.FindProperty("Total")!.GetComputedColumnSql();
var b = ctx.Model.FindEntityType(typeof(Teacher))!.FindProperty("Total")!.GetComputedColumnSql();
Debug.Assert(string.Equals(a ?? "", b ?? "", StringComparison.OrdinalIgnoreCase), $"Computed SQL mismatch: {a} vs {b}"); Try / catch
try { using var ctx = new MyContext(); _ = ctx.Model; }
catch (InvalidOperationException ex) when (ex.Message.Contains("different computed values"))
{ log.Error("Computed-column SQL mismatch on shared column: {Msg}", ex.Message); throw; } Prevention
- Define computed-column SQL once on a shared base or via a single IEntityTypeConfiguration.
- Use a startup model-build test to catch computed-SQL divergence early.
- Avoid copy-pasting computed SQL across siblings; reference one constant.
When it happens
Trigger: Sibling TPH types where one calls HasComputedColumnSql("[A] + [B]") and the other calls HasComputedColumnSql("[A] * 2") on a same-named column; an owned type and owner defining different computed SQL for a shared column; table splitting where each side supplies its own formula.
Common situations: Refactoring a computed formula on one branch of a hierarchy without updating the sibling; introducing a computed column on the owner side while an owned entity already defines one; copy-paste of entity config that left a stale formula.
Related errors
- '{entityType1}.{property1}' and '{entityType2}.{property2}'
- '{entityType1}.{property1}' and '{entityType2}.{property2}'
- '{entityType1}.{property1}' and '{entityType2}.{property2}'
- '{entityType1}.{property1}' and '{entityType2}.{property2}'
- '{entityType1}.{property1}' and '{entityType2}.{property2}'
AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06).
Data as JSON: /api/errors/118463c9ce40b692.
Report an issue: GitHub.