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

Fix API consistency errors in metadata #20267

Merged
merged 1 commit into from
Mar 17, 2020
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
9 changes: 7 additions & 2 deletions src/EFCore.Cosmos/Extensions/CosmosModelExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,18 @@ public static void SetDefaultContainer([NotNull] this IMutableModel model, [CanB
/// <param name="model"> The model. </param>
/// <param name="name"> The name to set. </param>
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
public static void SetDefaultContainer(
/// <returns> The configured value. </returns>
public static string SetDefaultContainer(
[NotNull] this IConventionModel model, [CanBeNull] string name, bool fromDataAnnotation = false)
=> model.SetOrRemoveAnnotation(
{
model.SetOrRemoveAnnotation(
CosmosAnnotationNames.ContainerName,
Check.NullButNotEmpty(name, nameof(name)),
fromDataAnnotation);

return name;
}

/// <summary>
/// Returns the configuration source for the default container name.
/// </summary>
Expand Down
9 changes: 7 additions & 2 deletions src/EFCore.Cosmos/Extensions/CosmosPropertyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,18 @@ public static void SetJsonPropertyName([NotNull] this IMutableProperty property,
/// <param name="property"> The property. </param>
/// <param name="name"> The name to set. </param>
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
public static void SetJsonPropertyName(
/// <returns> The configured value. </returns>
public static string SetJsonPropertyName(
[NotNull] this IConventionProperty property, [CanBeNull] string name, bool fromDataAnnotation = false)
=> property.SetOrRemoveAnnotation(
{
property.SetOrRemoveAnnotation(
CosmosAnnotationNames.PropertyName,
name,
fromDataAnnotation);

return name;
}

/// <summary>
/// Gets the <see cref="ConfigurationSource" /> the property name that the property is mapped to when targeting Cosmos.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public virtual void ProcessEntityTypeAdded(
/// <param name="relationshipBuilder"> The builder for the foreign key. </param>
/// <param name="context"> Additional information associated with convention execution. </param>
public virtual void ProcessForeignKeyOwnershipChanged(
IConventionRelationshipBuilder relationshipBuilder,
IConventionContext<IConventionRelationshipBuilder> context)
IConventionForeignKeyBuilder relationshipBuilder,
IConventionContext<bool?> context)
{
Check.NotNull(relationshipBuilder, nameof(relationshipBuilder));
Check.NotNull(context, nameof(context));
Expand All @@ -68,7 +68,7 @@ public virtual void ProcessForeignKeyOwnershipChanged(
&& entityType.BaseType == null
&& !entityType.GetDerivedTypes().Any())
{
entityType.Builder.HasNoDeclaredDiscriminator();
entityType.Builder.HasNoDiscriminator();
}
}

Expand All @@ -89,7 +89,7 @@ public virtual void ProcessForeignKeyRemoved(
&& entityType.BaseType == null
&& !entityType.GetDerivedTypes().Any())
{
entityType.Builder.HasNoDeclaredDiscriminator();
entityType.Builder.HasNoDiscriminator();
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/EFCore.Cosmos/Metadata/Conventions/StoreKeyConvention.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private static void Process(IConventionEntityTypeBuilder entityTypeBuilder)
var jObjectProperty = entityType.FindDeclaredProperty(JObjectPropertyName);
if (jObjectProperty != null)
{
entityType.Builder.RemoveUnusedShadowProperties(new[] { jObjectProperty });
entityType.Builder.HasNoUnusedShadowProperties(new[] { jObjectProperty });
}
}
}
Expand All @@ -132,8 +132,8 @@ public virtual void ProcessEntityTypeAdded(
/// <param name="relationshipBuilder"> The builder for the foreign key. </param>
/// <param name="context"> Additional information associated with convention execution. </param>
public virtual void ProcessForeignKeyOwnershipChanged(
IConventionRelationshipBuilder relationshipBuilder,
IConventionContext<IConventionRelationshipBuilder> context)
IConventionForeignKeyBuilder relationshipBuilder,
IConventionContext<bool?> context)
{
Check.NotNull(relationshipBuilder, nameof(relationshipBuilder));
Check.NotNull(context, nameof(context));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ protected virtual void AddNavigationProperties([NotNull] IMutableForeignKey fore
singularizePluralizer: null,
uniquifier: NavigationUniquifier);

foreignKey.HasDependentToPrincipal(dependentEndNavigationPropertyName);
foreignKey.SetDependentToPrincipal(dependentEndNavigationPropertyName);

if (foreignKey.DeclaringEntityType.IsKeyless)
{
Expand Down Expand Up @@ -886,7 +886,7 @@ protected virtual void AddNavigationProperties([NotNull] IMutableForeignKey fore
singularizePluralizer: null,
uniquifier: NavigationUniquifier);

foreignKey.HasPrincipalToDependent(principalEndNavigationPropertyName);
foreignKey.SetPrincipalToDependent(principalEndNavigationPropertyName);
}

// Stores the names of the EntityType itself and its Properties, but does not include any Navigation Properties
Expand Down
5 changes: 2 additions & 3 deletions src/EFCore.Proxies/Proxies/Internal/ProxyBindingRewriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using JetBrains.Annotations;
Expand Down Expand Up @@ -136,7 +135,7 @@ public virtual void ProcessModelFinalizing(IConventionModelBuilder modelBuilder,
},
proxyType));

foreach (var prop in entityType.GetProperties().Where(p => !p.IsShadowProperty()))
foreach (var prop in entityType.GetDeclaredProperties().Where(p => !p.IsShadowProperty()))
{
if (prop.PropertyInfo == null)
{
Expand All @@ -152,7 +151,7 @@ public virtual void ProcessModelFinalizing(IConventionModelBuilder modelBuilder,
}
}

foreach (var navigation in entityType.GetNavigations())
foreach (var navigation in entityType.GetDeclaredNavigations())
{
if (navigation.PropertyInfo == null)
{
Expand Down
115 changes: 84 additions & 31 deletions src/EFCore.Relational/Extensions/RelationalEntityTypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,18 @@ public static void SetTableName([NotNull] this IMutableEntityType entityType, [C
/// <param name="entityType"> The entity type to set the table name for. </param>
/// <param name="name"> The name to set. </param>
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
public static void SetTableName(
/// <returns> The configured table name. </returns>
public static string SetTableName(
[NotNull] this IConventionEntityType entityType, [CanBeNull] string name, bool fromDataAnnotation = false)
=> entityType.SetAnnotation(
{
entityType.SetAnnotation(
RelationalAnnotationNames.TableName,
Check.NullButNotEmpty(name, nameof(name)),
fromDataAnnotation);

return name;
}

/// <summary>
/// Gets the <see cref="ConfigurationSource" /> for the table name.
/// </summary>
Expand Down Expand Up @@ -146,13 +151,18 @@ public static void SetSchema([NotNull] this IMutableEntityType entityType, [CanB
/// <param name="entityType"> The entity type to set the schema for. </param>
/// <param name="value"> The value to set. </param>
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
public static void SetSchema(
/// <returns> The configured value. </returns>
public static string SetSchema(
[NotNull] this IConventionEntityType entityType, [CanBeNull] string value, bool fromDataAnnotation = false)
=> entityType.SetOrRemoveAnnotation(
{
entityType.SetOrRemoveAnnotation(
RelationalAnnotationNames.Schema,
Check.NullButNotEmpty(value, nameof(value)),
fromDataAnnotation);

return value;
}

/// <summary>
/// Gets the <see cref="ConfigurationSource" /> for the database schema.
/// </summary>
Expand Down Expand Up @@ -251,13 +261,18 @@ public static void SetViewName([NotNull] this IMutableEntityType entityType, [Ca
/// <param name="entityType"> The entity type to set the view name for. </param>
/// <param name="name"> The name to set. </param>
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
public static void SetViewName(
/// <returns> The configured value. </returns>
public static string SetViewName(
[NotNull] this IConventionEntityType entityType, [CanBeNull] string name, bool fromDataAnnotation = false)
=> entityType.SetAnnotation(
{
entityType.SetAnnotation(
RelationalAnnotationNames.ViewName,
Check.NullButNotEmpty(name, nameof(name)),
fromDataAnnotation);

return name;
}

/// <summary>
/// Gets the <see cref="ConfigurationSource" /> for the view name.
/// </summary>
Expand Down Expand Up @@ -310,13 +325,18 @@ public static void SetViewSchema([NotNull] this IMutableEntityType entityType, [
/// <param name="entityType"> The entity type to set the view schema for. </param>
/// <param name="value"> The value to set. </param>
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
public static void SetViewSchema(
/// <returns> The configured schema. </returns>
public static string SetViewSchema(
[NotNull] this IConventionEntityType entityType, [CanBeNull] string value, bool fromDataAnnotation = false)
=> entityType.SetOrRemoveAnnotation(
{
entityType.SetOrRemoveAnnotation(
RelationalAnnotationNames.ViewSchema,
Check.NullButNotEmpty(value, nameof(value)),
fromDataAnnotation);

return value;
}

/// <summary>
/// Gets the <see cref="ConfigurationSource" /> for the view schema.
/// </summary>
Expand All @@ -343,6 +363,19 @@ public static ICheckConstraint FindCheckConstraint(
return CheckConstraint.FindCheckConstraint(entityType, name);
}

/// <summary>
/// Finds an <see cref="IMutableCheckConstraint" /> with the given name.
/// </summary>
/// <param name="entityType"> The entity type to find the check constraint for. </param>
/// <param name="name"> The check constraint name. </param>
/// <returns>
/// The <see cref="IMutableCheckConstraint" /> or <c>null</c> if no check constraint with the
/// given name in the given entity type was found.
/// </returns>
public static IMutableCheckConstraint FindCheckConstraint(
[NotNull] this IMutableEntityType entityType, [NotNull] string name)
=> (IMutableCheckConstraint)((IEntityType)entityType).FindCheckConstraint(name);

/// <summary>
/// Finds an <see cref="IConventionCheckConstraint" /> with the given name.
/// </summary>
Expand All @@ -364,7 +397,7 @@ public static IConventionCheckConstraint FindCheckConstraint(
/// <param name="name"> The check constraint name. </param>
/// <param name="sql"> The logical constraint sql used in the check constraint. </param>
/// <returns> The new check constraint. </returns>
public static ICheckConstraint AddCheckConstraint(
public static IMutableCheckConstraint AddCheckConstraint(
[NotNull] this IMutableEntityType entityType,
[NotNull] string name,
[NotNull] string sql)
Expand Down Expand Up @@ -403,30 +436,22 @@ public static IConventionCheckConstraint AddCheckConstraint(
/// </summary>
/// <param name="entityType"> The entity type to remove the check constraint from. </param>
/// <param name="name"> The check constraint name to be removed. </param>
/// <returns>
/// True if the <see cref="ICheckConstraint" /> is successfully found and removed; otherwise, false.
/// </returns>
public static bool RemoveCheckConstraint(
/// <returns> The removed <see cref="IMutableCheckConstraint" />. </returns>
public static IMutableCheckConstraint RemoveCheckConstraint(
[NotNull] this IMutableEntityType entityType,
[NotNull] string name)
{
Check.NotEmpty(name, nameof(name));

return CheckConstraint.RemoveCheckConstraint(entityType, name);
}
=> CheckConstraint.RemoveCheckConstraint(entityType, Check.NotEmpty(name, nameof(name)));

/// <summary>
/// Removes the <see cref="IConventionCheckConstraint" /> with the given name.
/// </summary>
/// <param name="entityType"> The entity type to remove the check constraint from. </param>
/// <param name="name"> The check constraint name. </param>
/// <returns>
/// True if the <see cref="IConventionCheckConstraint" /> is successfully found and removed; otherwise, false.
/// </returns>
public static bool RemoveCheckConstraint(
/// <returns> The removed <see cref="IConventionCheckConstraint" />. </returns>
public static IConventionCheckConstraint RemoveCheckConstraint(
[NotNull] this IConventionEntityType entityType,
[NotNull] string name)
=> RemoveCheckConstraint((IMutableEntityType)entityType, name);
=> CheckConstraint.RemoveCheckConstraint((IMutableEntityType)entityType, Check.NotEmpty(name, nameof(name)));

/// <summary>
/// Returns all <see cref="ICheckConstraint" /> contained in the entity type.
Expand All @@ -436,30 +461,58 @@ public static IEnumerable<ICheckConstraint> GetCheckConstraints([NotNull] this I
=> CheckConstraint.GetCheckConstraints(entityType);

/// <summary>
/// Returns the comment for the column this property is mapped to.
/// Returns all <see cref="IMutableCheckConstraint" /> contained in the entity type.
/// </summary>
/// <param name="entityType"> The entity type to get the check constraints for. </param>
public static IEnumerable<IMutableCheckConstraint> GetCheckConstraints([NotNull] this IMutableEntityType entityType)
=> CheckConstraint.GetCheckConstraints(entityType);

/// <summary>
/// Returns all <see cref="IConventionCheckConstraint" /> contained in the entity type.
/// </summary>
/// <param name="entityType"> The entity type to get the check constraints for. </param>
public static IEnumerable<IConventionCheckConstraint> GetCheckConstraints([NotNull] this IConventionEntityType entityType)
=> CheckConstraint.GetCheckConstraints(entityType);

/// <summary>
/// Returns the comment for the table this entity is mapped to.
/// </summary>
/// <param name="entityType"> The entity type. </param>
/// <returns> The comment for the column this property is mapped to. </returns>
/// <returns> The comment for the table this entity is mapped to. </returns>
public static string GetComment([NotNull] this IEntityType entityType)
=> (string)entityType[RelationalAnnotationNames.Comment];

/// <summary>
/// Configures a comment to be applied to the column this property is mapped to.
/// Configures a comment to be applied to the table this entity is mapped to.
/// </summary>
/// <param name="entityType"> The entity type. </param>
/// <param name="comment"> The comment for the column. </param>
/// <param name="comment"> The comment for the table this entity is mapped to. </param>
public static void SetComment([NotNull] this IMutableEntityType entityType, [CanBeNull] string comment)
=> entityType.SetOrRemoveAnnotation(RelationalAnnotationNames.Comment, comment);

/// <summary>
/// Configures a comment to be applied to the column this property is mapped to.
/// Configures a comment to be applied to the table this entity is mapped to.
/// </summary>
/// <param name="entityType"> The entity type. </param>
/// <param name="comment"> The comment for the column. </param>
/// <param name="comment"> The comment for the table. </param>
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
public static void SetComment(
/// <returns> The configured comment. </returns>
public static string SetComment(
[NotNull] this IConventionEntityType entityType, [CanBeNull] string comment, bool fromDataAnnotation = false)
=> entityType.SetOrRemoveAnnotation(RelationalAnnotationNames.Comment, comment, fromDataAnnotation);
{
entityType.SetOrRemoveAnnotation(RelationalAnnotationNames.Comment, comment, fromDataAnnotation);

return comment;
}

/// <summary>
/// Gets the <see cref="ConfigurationSource" /> for the table comment.
/// </summary>
/// <param name="entityType"> The entity type to find configuration source for. </param>
/// <returns> The <see cref="ConfigurationSource" /> for the table comment. </returns>
public static ConfigurationSource? GetCommentConfigurationSource([NotNull] this IConventionEntityType entityType)
=> entityType.FindAnnotation(RelationalAnnotationNames.Comment)
?.GetConfigurationSource();

/// <summary>
/// Gets a value indicating whether the entity type is ignored by Migrations.
Expand Down
Loading