Skip to content

Commit

Permalink
Map owned reference types to the same view as the owner by default.
Browse files Browse the repository at this point in the history
Fixes #18298
  • Loading branch information
AndriySvyryd committed Oct 21, 2019
1 parent c480280 commit fd6448e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
20 changes: 18 additions & 2 deletions src/EFCore.Relational/Extensions/RelationalEntityTypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,26 @@ public static bool IsIgnoredByMigrations([NotNull] this IEntityType entityType)
return entityType.BaseType.IsIgnoredByMigrations();
}

if (entityType.GetDefiningQuery() != null)
{
return true;
}

var viewDefinition = entityType.FindAnnotation(RelationalAnnotationNames.ViewDefinition);
if (viewDefinition == null)
{
var ownership = entityType.FindOwnership();
if (ownership != null
&& ownership.IsUnique
&& entityType.FindAnnotation(RelationalAnnotationNames.TableName) == null)
{
return ownership.PrincipalEntityType.IsIgnoredByMigrations();
}

return false;
}

return (viewDefinition != null && viewDefinition.Value == null)
|| entityType.GetDefiningQuery() != null;
return viewDefinition.Value == null;
}
}
}
18 changes: 12 additions & 6 deletions src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2385,9 +2385,12 @@ public virtual TableMapping FindTargetTable(IEntityType entityType)
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual T FindSource<T>([NotNull] T target)
=> _targetToSource.TryGetValue(target, out var source)
? (T)source
: default;
where T : class
=> target == null
? null
: _targetToSource.TryGetValue(target, out var source)
? (T)source
: null;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down Expand Up @@ -2426,9 +2429,12 @@ public virtual IProperty FindSource([NotNull] IProperty target)
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual T FindTarget<T>([NotNull] T source)
=> _sourceToTarget.TryGetValue(source, out var target)
? (T)target
: default;
where T : class
=> source == null
? null
: _sourceToTarget.TryGetValue(source, out var target)
? (T)target
: null;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ public void Model_differ_does_not_detect_views()
result => Assert.Equal(0, result.Count));
}

[ConditionalFact]
public void Model_differ_does_not_detect_views_with_owned_types()
{
Execute(
_ => { },
target => target.Entity<Order>(
x =>
{
x.ToView("Orders");
x.OwnsOne(y => y.Billing);
x.OwnsOne(y => y.Shipping);
}),
upOperations => Assert.Equal(0, upOperations.Count));
}

[ConditionalFact]
public void Model_differ_does_not_detect_queries()
{
Expand Down

0 comments on commit fd6448e

Please sign in to comment.