Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map owned reference types to the same view as the owner by default. #18495

Merged
merged 1 commit into from
Oct 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
}
22 changes: 14 additions & 8 deletions src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2384,10 +2384,13 @@ public virtual TableMapping FindTargetTable(IEntityType entityType)
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// 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;
public virtual T FindSource<T>([CanBeNull] T target)
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 @@ -2425,10 +2428,13 @@ public virtual IProperty FindSource([NotNull] IProperty target)
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// 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;
public virtual T FindTarget<T>([CanBeNull] T source)
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