Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
roji committed Mar 9, 2022
1 parent f60ca2d commit 80ba153
Show file tree
Hide file tree
Showing 28 changed files with 850 additions and 196 deletions.
2 changes: 1 addition & 1 deletion src/EFCore.Analyzers/InternalUsageDiagnosticAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public sealed class InternalUsageDiagnosticAnalyzer : DiagnosticAnalyzer
private static readonly int EFLen = "EntityFrameworkCore".Length;

private static readonly DiagnosticDescriptor Descriptor
= new DiagnosticDescriptor(
= new(
Id,
title: AnalyzerStrings.InternalUsageTitle,
messageFormat: AnalyzerStrings.InternalUsageMessageFormat,
Expand Down
198 changes: 198 additions & 0 deletions src/EFCore.Relational/Extensions/RelationalEntityTypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public static class RelationalEntityTypeExtensions
/// </summary>
public static readonly string DefaultQueryNameBase = "MappedSqlQuery";

#region Table mapping

/// <summary>
/// Returns the name of the table to which the entity type is mapped
/// or <see langword="null" /> if not mapped to a table.
Expand Down Expand Up @@ -266,6 +268,10 @@ public static IEnumerable<ITableMapping> GetTableMappings(this IEntityType entit
RelationalAnnotationNames.TableMappings)
?? Enumerable.Empty<ITableMapping>();

#endregion Table mapping

#region View mapping

/// <summary>
/// Returns the name of the view to which the entity type is mapped or <see langword="null" /> if not mapped to a view.
/// </summary>
Expand Down Expand Up @@ -430,6 +436,10 @@ public static IEnumerable<IViewMapping> GetViewMappings(this IEntityType entityT
RelationalAnnotationNames.ViewMappings)
?? Enumerable.Empty<IViewMapping>();

#endregion View mapping

#region SQL query mapping

/// <summary>
/// Gets the default SQL query name that would be used for this entity type when mapped using
/// <see cref="O:RelationalEntityTypeBuilderExtensions.ToSqlQuery" />.
Expand Down Expand Up @@ -495,6 +505,10 @@ public static IEnumerable<ISqlQueryMapping> GetSqlQueryMappings(this IEntityType
RelationalAnnotationNames.SqlQueryMappings)
?? Enumerable.Empty<ISqlQueryMapping>();

#endregion SQL query mapping

#region Function mapping

/// <summary>
/// Returns the name of the function to which the entity type is mapped or <see langword="null" /> if not mapped to a function.
/// </summary>
Expand Down Expand Up @@ -551,6 +565,10 @@ public static IEnumerable<IFunctionMapping> GetFunctionMappings(this IEntityType
RelationalAnnotationNames.FunctionMappings)
?? Enumerable.Empty<IFunctionMapping>();

#endregion Function mapping

#region Check constraint

/// <summary>
/// Finds an <see cref="IReadOnlyCheckConstraint" /> with the given name.
/// </summary>
Expand Down Expand Up @@ -752,6 +770,10 @@ public static IEnumerable<IConventionCheckConstraint> GetDeclaredCheckConstraint
public static IEnumerable<ICheckConstraint> GetDeclaredCheckConstraints(this IEntityType entityType)
=> CheckConstraint.GetDeclaredCheckConstraints(entityType).Cast<ICheckConstraint>();

#endregion Check constraint

#region Comment

/// <summary>
/// Returns the comment for the table this entity is mapped to.
/// </summary>
Expand Down Expand Up @@ -796,6 +818,8 @@ public static void SetComment(this IMutableEntityType entityType, string? commen
=> entityType.FindAnnotation(RelationalAnnotationNames.Comment)
?.GetConfigurationSource();

#endregion Comment

/// <summary>
/// Gets the foreign keys for the given entity type that point to other entity types
/// sharing the same table-like store object.
Expand Down Expand Up @@ -892,6 +916,8 @@ public static IEnumerable<IForeignKey> FindRowInternalForeignKeys(
// ReSharper disable once RedundantCast
=> ((IReadOnlyEntityType)entityType).FindRowInternalForeignKeys(storeObject).Cast<IForeignKey>();

#region IsTableExcludedFromMigrations

/// <summary>
/// Gets a value indicating whether the associated table is ignored by Migrations.
/// </summary>
Expand Down Expand Up @@ -957,4 +983,176 @@ public static void SetIsTableExcludedFromMigrations(this IMutableEntityType enti
this IConventionEntityType entityType)
=> entityType.FindAnnotation(RelationalAnnotationNames.IsTableExcludedFromMigrations)
?.GetConfigurationSource();

#endregion IsTableExcludedFromMigrations

#region Trigger

/// <summary>
/// Finds a trigger with the given name.
/// </summary>
/// <param name="entityType">The entity type to find the sequence on.</param>
/// <param name="name">The trigger name.</param>
/// <returns>The trigger or <see langword="null" /> if no trigger with the given name was found.</returns>
public static IReadOnlyTrigger? FindTrigger(this IReadOnlyEntityType entityType, string name)
=> Trigger.FindTrigger(entityType, Check.NotEmpty(name, nameof(name)));

/// <summary>
/// Finds a trigger with the given name.
/// </summary>
/// <param name="entityType">The entity type to find the sequence on.</param>
/// <param name="name">The trigger name.</param>
/// <returns>The trigger or <see langword="null" /> if no trigger with the given name was found.</returns>
public static IMutableTrigger? FindTrigger(this IMutableEntityType entityType, string name)
=> (IMutableTrigger?)((IReadOnlyEntityType)entityType).FindTrigger(name);

/// <summary>
/// Finds a trigger with the given name.
/// </summary>
/// <param name="entityType">The entity type to find the sequence on.</param>
/// <param name="name">The trigger name.</param>
/// <returns>The trigger or <see langword="null" /> if no trigger with the given name was found.</returns>
public static IConventionTrigger? FindTrigger(this IConventionEntityType entityType, string name)
=> (IConventionTrigger?)((IReadOnlyEntityType)entityType).FindTrigger(name);

/// <summary>
/// Finds a trigger with the given name.
/// </summary>
/// <param name="entityType">The entity type to find the sequence on.</param>
/// <param name="name">The trigger name.</param>
/// <returns>The trigger or <see langword="null" /> if no trigger with the given name was found.</returns>
public static ITrigger? FindTrigger(this IEntityType entityType, string name)
=> (ITrigger?)((IReadOnlyEntityType)entityType).FindTrigger(name);

/// <summary>
/// Either returns the existing <see cref="IMutableTrigger" /> with the given name or creates a new trigger with the given name.
/// </summary>
/// <param name="entityType">The entity type to add the trigger to.</param>
/// <param name="name">The trigger name.</param>
/// <returns>The trigger.</returns>
public static IMutableTrigger AddTrigger(this IMutableEntityType entityType, string name)
{
Check.NotEmpty(name, nameof(name));

return new Trigger(entityType, name, ConfigurationSource.Explicit);
}

/// <summary>
/// Either returns the existing <see cref="IMutableTrigger" /> with the given name or creates a new trigger with the given name.
/// </summary>
/// <param name="entityType">The entityType to add the trigger to.</param>
/// <param name="name">The trigger name.</param>
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
/// <returns>The trigger.</returns>
public static IConventionTrigger? AddTrigger(
this IConventionEntityType entityType,
string name,
bool fromDataAnnotation = false)
{
Check.NotEmpty(name, nameof(name));

return new Trigger(
(IMutableEntityType)entityType, name,
fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention);
}

/// <summary>
/// Removes the <see cref="IMutableTrigger" /> with the given name.
/// </summary>
/// <param name="entityType">The entityType to find the trigger in.</param>
/// <param name="name">The trigger name.</param>
/// <returns>
/// The removed <see cref="IMutableTrigger" /> or <see langword="null" /> if no trigger with the given name was found.
/// </returns>
public static IMutableTrigger? RemoveTrigger(this IMutableEntityType entityType, string name)
=> Trigger.RemoveTrigger(entityType, name);

/// <summary>
/// Removes the <see cref="IConventionTrigger" /> with the given name.
/// </summary>
/// <param name="entityType">The entityType to find the trigger in.</param>
/// <param name="name">The trigger name.</param>
/// <returns>
/// The removed <see cref="IMutableTrigger" /> or <see langword="null" /> if no trigger with the given name was found.
/// </returns>
public static IConventionTrigger? RemoveTrigger(this IConventionEntityType entityType, string name)
=> Trigger.RemoveTrigger((IMutableEntityType)entityType, name);

/// <summary>
/// Returns all triggers on the entity type.
/// </summary>
/// <param name="entityType">The entity type to get the triggers on.</param>
public static IEnumerable<IReadOnlyTrigger> GetTriggers(this IReadOnlyEntityType entityType)
=> Trigger.GetTriggers(entityType);

/// <summary>
/// Returns all triggers on the entity type.
/// </summary>
/// <param name="entityType">The entity type to get the triggers on.</param>
public static IEnumerable<IMutableTrigger> GetTriggers(this IMutableEntityType entityType)
=> Trigger.GetTriggers(entityType).Cast<IMutableTrigger>();

/// <summary>
/// Returns all triggers on the entity type.
/// </summary>
/// <param name="entityType">The entity type to get the triggers on.</param>
public static IEnumerable<IConventionTrigger> GetTriggers(this IConventionEntityType entityType)
=> Trigger.GetTriggers(entityType).Cast<IConventionTrigger>();

/// <summary>
/// Returns all triggers on the entity type.
/// </summary>
/// <param name="entityType">The entity type to get the triggers on.</param>
public static IEnumerable<ITrigger> GetTriggers(this IEntityType entityType)
=> Trigger.GetTriggers(entityType).Cast<ITrigger>();

/// <summary>
/// Returns all triggers on the entity type.
/// </summary>
/// <param name="entityType">The entity type to get the triggers on.</param>
/// <remarks>
/// This method does not return triggers declared on base types.
/// It is useful when iterating over all entity types to avoid processing the same trigger more than once.
/// Use <see cref="GetTriggers(IReadOnlyEntityType)" /> to also return triggers declared on base types.
/// </remarks>
public static IEnumerable<IReadOnlyTrigger> GetDeclaredTriggers(this IReadOnlyEntityType entityType)
=> Trigger.GetDeclaredTriggers(entityType);

/// <summary>
/// Returns all triggers on the entity type.
/// </summary>
/// <param name="entityType">The entity type to get the triggers on.</param>
/// <remarks>
/// This method does not return triggers declared on base types.
/// It is useful when iterating over all entity types to avoid processing the same trigger more than once.
/// Use <see cref="GetTriggers(IMutableEntityType)" /> to also return triggers declared on base types.
/// </remarks>
public static IEnumerable<IMutableTrigger> GetDeclaredTriggers(this IMutableEntityType entityType)
=> Trigger.GetDeclaredTriggers(entityType).Cast<IMutableTrigger>();

/// <summary>
/// Returns all triggers on the entity type.
/// </summary>
/// <param name="entityType">The entity type to get the triggers on.</param>
/// <remarks>
/// This method does not return triggers declared on base types.
/// It is useful when iterating over all entity types to avoid processing the same trigger more than once.
/// Use <see cref="GetTriggers(IConventionEntityType)" /> to also return triggers declared on base types.
/// </remarks>
public static IEnumerable<IConventionTrigger> GetDeclaredTriggers(this IConventionEntityType entityType)
=> Trigger.GetDeclaredTriggers(entityType).Cast<IConventionTrigger>();

/// <summary>
/// Returns all triggers on the entity type.
/// </summary>
/// <param name="entityType">The entity type to get the triggers on.</param>
/// <remarks>
/// This method does not return triggers declared on base types.
/// It is useful when iterating over all entity types to avoid processing the same trigger more than once.
/// Use <see cref="GetTriggers(IEntityType)" /> to also return triggers declared on base types.
/// </remarks>
public static IEnumerable<ITrigger> GetDeclaredTriggers(this IEntityType entityType)
=> Trigger.GetDeclaredTriggers(entityType).Cast<ITrigger>();

#endregion Trigger
}
114 changes: 0 additions & 114 deletions src/EFCore.Relational/Extensions/RelationalModelExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -529,118 +529,4 @@ public static void SetCollation(this IMutableModel model, string? value)
=> model.FindAnnotation(RelationalAnnotationNames.Collation)?.GetConfigurationSource();

#endregion Collation

#region Trigger

/// <summary>
/// Finds a trigger with the given name.
/// </summary>
/// <param name="entityType">The entity type to find the sequence on.</param>
/// <param name="name">The trigger name.</param>
/// <returns>The trigger or <see langword="null" /> if no trigger with the given name was found.</returns>
public static IReadOnlyTrigger? FindTrigger(this IReadOnlyEntityType entityType, string name)
=> Trigger.FindTrigger(entityType, Check.NotEmpty(name, nameof(name)));

/// <summary>
/// Finds a trigger with the given name.
/// </summary>
/// <param name="entityType">The entity type to find the sequence on.</param>
/// <param name="name">The trigger name.</param>
/// <returns>The trigger or <see langword="null" /> if no trigger with the given name was found.</returns>
public static IMutableTrigger? FindTrigger(this IMutableEntityType entityType, string name)
=> (IMutableTrigger?)((IReadOnlyEntityType)entityType).FindTrigger(name);

/// <summary>
/// Finds a trigger with the given name.
/// </summary>
/// <param name="entityType">The entity type to find the sequence on.</param>
/// <param name="name">The trigger name.</param>
/// <returns>The trigger or <see langword="null" /> if no trigger with the given name was found.</returns>
public static IConventionTrigger? FindTrigger(this IConventionEntityType entityType, string name)
=> (IConventionTrigger?)((IReadOnlyEntityType)entityType).FindTrigger(name);

/// <summary>
/// Finds a trigger with the given name.
/// </summary>
/// <param name="entityType">The entity type to find the sequence on.</param>
/// <param name="name">The trigger name.</param>
/// <returns>The trigger or <see langword="null" /> if no trigger with the given name was found.</returns>
public static ITrigger? FindTrigger(this IEntityType entityType, string name)
=> (ITrigger?)((IReadOnlyEntityType)entityType).FindTrigger(name);

/// <summary>
/// Either returns the existing <see cref="IMutableTrigger" /> with the given name or creates a new trigger with the given name.
/// </summary>
/// <param name="entityType">The entity type to add the trigger to.</param>
/// <param name="name">The trigger name.</param>
/// <returns>The trigger.</returns>
public static IMutableTrigger AddTrigger(this IMutableEntityType entityType, string name)
=> Trigger.AddTrigger(entityType, name, ConfigurationSource.Explicit);

/// <summary>
/// Either returns the existing <see cref="IMutableTrigger" /> with the given name or creates a new trigger with the given name.
/// </summary>
/// <param name="entityType">The entityType to add the trigger to.</param>
/// <param name="name">The trigger name.</param>
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
/// <returns>The trigger.</returns>
public static IConventionTrigger? AddTrigger(
this IConventionEntityType entityType,
string name,
bool fromDataAnnotation = false)
=> Trigger.AddTrigger(
(IMutableEntityType)entityType, name,
fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention);

/// <summary>
/// Removes the <see cref="IMutableTrigger" /> with the given name.
/// </summary>
/// <param name="entityType">The entityType to find the trigger in.</param>
/// <param name="name">The trigger name.</param>
/// <returns>
/// The removed <see cref="IMutableTrigger" /> or <see langword="null" /> if no trigger with the given name was found.
/// </returns>
public static IMutableTrigger? RemoveTrigger(this IMutableEntityType entityType, string name)
=> Trigger.RemoveTrigger(entityType, name);

/// <summary>
/// Removes the <see cref="IConventionTrigger" /> with the given name.
/// </summary>
/// <param name="entityType">The entityType to find the trigger in.</param>
/// <param name="name">The trigger name.</param>
/// <returns>
/// The removed <see cref="IMutableTrigger" /> or <see langword="null" /> if no trigger with the given name was found.
/// </returns>
public static IConventionTrigger? RemoveTrigger(this IConventionEntityType entityType, string name)
=> Trigger.RemoveTrigger((IMutableEntityType)entityType, name);

/// <summary>
/// Returns all triggers on the entity type.
/// </summary>
/// <param name="entityType">The entity type to get the triggers on.</param>
public static IEnumerable<ITrigger> GetTriggers(this IEntityType entityType)
=> Trigger.GetTriggers(entityType);

/// <summary>
/// Returns all triggers on the entity type.
/// </summary>
/// <param name="entityType">The entity type to get the triggers on.</param>
public static IEnumerable<IMutableTrigger> GetTriggers(this IMutableEntityType entityType)
=> Trigger.GetTriggers(entityType).Cast<IMutableTrigger>();

/// <summary>
/// Returns all triggers on the entity type.
/// </summary>
/// <param name="entityType">The entity type to get the triggers on.</param>
public static IEnumerable<IConventionTrigger> GetTriggers(this IConventionEntityType entityType)
=> Trigger.GetTriggers(entityType).Cast<IConventionTrigger>();

/// <summary>
/// Returns all triggers on the entity type.
/// </summary>
/// <param name="entityType">The entity type to get the triggers on.</param>
public static IEnumerable<IReadOnlyTrigger> GetTriggers(this IReadOnlyEntityType entityType)
=> Trigger.GetTriggers(entityType);

#endregion Trigger
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ public interface IConventionCheckConstraintBuilder : IConventionAnnotatableBuild
/// </summary>
/// <param name="name">The database name of the check constraint.</param>
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
/// <returns>
/// The same builder instance if the configuration was applied,
/// <see langword="null" /> otherwise.
/// </returns>
/// <returns>The same builder instance if the configuration was applied, <see langword="null" /> otherwise.</returns>
IConventionCheckConstraintBuilder? HasName(string? name, bool fromDataAnnotation = false);

/// <summary>
Expand Down
Loading

0 comments on commit 80ba153

Please sign in to comment.