dotnet/efcore · error · InvalidOperationException
Both ' ' and ' ' are mapped to the view ' '. All the entity…
Error message
Both '{entityType}' and '{otherEntityType}' are mapped to the view '{view}'. All the entity types in a non-TPH hierarchy (one that doesn't have a discriminator) must be mapped to different views. See https://go.microsoft.com/fwlink/?linkid=2130430 for more information. What it means
Thrown inside ValidateNonTphMapping when two entity types in a non-TPH hierarchy resolve to the same View StoreObjectIdentifier. Like the table clash (426) but for view mappings — each type in TPT/TPC must map to a distinct view.
Solutions
- Map each type to its own view name.
- Switch to TPH if a single shared view is intended.
- Remove conflicting ToView calls and let mapping differ per type.
Example fix
// before
modelBuilder.UseTptMappingStrategy();
modelBuilder.Entity<Customer>().ToView("v_People");
modelBuilder.Entity<Vendor>().ToView("v_People"); // throws 427
// after
modelBuilder.Entity<Customer>().ToView("v_Customers");
modelBuilder.Entity<Vendor>().ToView("v_Vendors"); Defensive patterns
Strategy: validation
Validate before calling
foreach (var root in modelBuilder.Model.GetEntityTypes().Where(t => t.BaseType == null))
{
var strategy = root.GetMappingStrategy();
if (strategy != RelationalAnnotationNames.TptMappingStrategy
&& strategy != RelationalAnnotationNames.TpcMappingStrategy) continue;
var views = new HashSet<string>();
foreach (var et in root.GetDerivedTypesInclusive())
{
var so = StoreObjectIdentifier.Create(et, StoreObjectType.View);
if (so != null && !views.Add(so.Value.Name))
throw new InvalidOperationException($"View '{so.Value.Name}' used by multiple types in {root.DisplayName()} hierarchy.");
}
} Prevention
- In TPT/TPC, give each type a unique ToView name.
- Use TPH if a single shared view is intended.
- Add a view-collision check in your model test.
When it happens
Trigger: Two types in a TPT/TPC hierarchy call ToView("SameView"), producing the same view StoreObjectIdentifier for sibling types.
Common situations: Backing a TPT/TPC hierarchy with database views and reusing a view name across types; copy-pasting ToView calls; refactor that merged view names.
Related errors
- Both ' ' and ' ' are mapped to the table ' '. All the…
- Both ' ' and ' ' are mapped to the stored procedure ' '…
- The entity type ' ' is not mapped, so by default the owned…
- The mapping strategy
- The mapping strategy
AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11).
Data as JSON: /api/errors/ac996f347c7b4766.
Report an issue: GitHub.
Appendix: source
Thrown at src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs:2245
entityType.DisplayName(),
unmappedOwnedType.FindOwnership()!.PrincipalToDependent?.Name,
unmappedOwnedType.DisplayName(),
storeObjectType));
}
continue;
}
if (derivedTypes.TryGetValue(storeObject.Value, out var otherType))
{
switch (storeObjectType)
{
case StoreObjectType.Table:
throw new InvalidOperationException(
RelationalStrings.NonTphTableClash(
entityType.DisplayName(), otherType.DisplayName(), storeObject.Value.DisplayName()));
case StoreObjectType.View:
throw new InvalidOperationException(
RelationalStrings.NonTphViewClash(
entityType.DisplayName(), otherType.DisplayName(), storeObject.Value.DisplayName()));
case StoreObjectType.InsertStoredProcedure:
case StoreObjectType.DeleteStoredProcedure:
case StoreObjectType.UpdateStoredProcedure:
throw new InvalidOperationException(
RelationalStrings.NonTphStoredProcedureClash(
entityType.DisplayName(), otherType.DisplayName(), storeObject.Value.DisplayName()));
}
}
if (isTpc)
{
var rowInternalFk = entityType.FindDeclaredReferencingRowInternalForeignKeys(storeObject.Value)
.FirstOrDefault();
if (rowInternalFk != null
&& entityType.GetDirectlyDerivedTypes().Any())
{View on GitHub (pinned to 3a2006ef56)