From 6c2c153ae4a3f2efab9278d414656f639cd39047 Mon Sep 17 00:00:00 2001 From: Kev Ritchie <65573253+KevRitchie@users.noreply.github.com> Date: Mon, 18 Oct 2021 20:11:36 +0100 Subject: [PATCH 1/3] Add Migration name check --- src/ef/Commands/MigrationsAddCommand.cs | 6 +++ src/ef/Properties/Resources.Designer.cs | 6 +++ src/ef/Properties/Resources.resx | 57 +++++++++++++------------ 3 files changed, 42 insertions(+), 27 deletions(-) diff --git a/src/ef/Commands/MigrationsAddCommand.cs b/src/ef/Commands/MigrationsAddCommand.cs index 7115820216a..112244e3f8f 100644 --- a/src/ef/Commands/MigrationsAddCommand.cs +++ b/src/ef/Commands/MigrationsAddCommand.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System; using System.Collections; using Microsoft.EntityFrameworkCore.Tools.Properties; @@ -13,6 +14,11 @@ protected override void Validate() { base.Validate(); + if (string.Equals(_name!.Value, "migration", StringComparison.OrdinalIgnoreCase)) + { + throw new CommandException(Resources.CircularBaseClassDependency); + } + if (string.IsNullOrEmpty(_name!.Value)) { throw new CommandException(Resources.MissingArgument(_name.Name)); diff --git a/src/ef/Properties/Resources.Designer.cs b/src/ef/Properties/Resources.Designer.cs index 9e7775be902..5c8cee3bd02 100644 --- a/src/ef/Properties/Resources.Designer.cs +++ b/src/ef/Properties/Resources.Designer.cs @@ -635,6 +635,12 @@ public static string WritingFile(object? file) GetString("WritingFile", nameof(file)), file); + /// + /// You cannot add a migration with the name 'Migration'. + /// + public static string CircularBaseClassDependency + => GetString("CircularBaseClassDependency"); + private static string GetString(string name, params string[] formatterNames) { var value = _resourceManager.GetString(name)!; diff --git a/src/ef/Properties/Resources.resx b/src/ef/Properties/Resources.resx index b29d432e76e..b893a40216b 100644 --- a/src/ef/Properties/Resources.resx +++ b/src/ef/Properties/Resources.resx @@ -1,17 +1,17 @@  - @@ -402,4 +402,7 @@ Writing '{file}'... + + You cannot add a migration with the name 'Migration'. + \ No newline at end of file From bf4b8240a584a4e2e73dff268b1e537d3ef623ce Mon Sep 17 00:00:00 2001 From: Kev Ritchie <65573253+KevRitchie@users.noreply.github.com> Date: Wed, 27 Oct 2021 20:54:50 +0100 Subject: [PATCH 2/3] Add migration name check --- src/EFCore.Design/Migrations/Design/MigrationsScaffolder.cs | 5 +++++ src/EFCore.Design/Properties/DesignStrings.Designer.cs | 6 ++++++ src/EFCore.Design/Properties/DesignStrings.resx | 3 +++ 3 files changed, 14 insertions(+) diff --git a/src/EFCore.Design/Migrations/Design/MigrationsScaffolder.cs b/src/EFCore.Design/Migrations/Design/MigrationsScaffolder.cs index 6685df740d5..04ead0dca15 100644 --- a/src/EFCore.Design/Migrations/Design/MigrationsScaffolder.cs +++ b/src/EFCore.Design/Migrations/Design/MigrationsScaffolder.cs @@ -82,6 +82,11 @@ public virtual ScaffoldedMigration ScaffoldMigration( { Check.NotEmpty(migrationName, nameof(migrationName)); + if (string.Equals(migrationName, "migration", StringComparison.OrdinalIgnoreCase)) + { + throw new OperationException(DesignStrings.CircularBaseClassDependency); + } + if (Dependencies.MigrationsAssembly.FindMigrationId(migrationName) != null) { throw new OperationException(DesignStrings.DuplicateMigrationName(migrationName)); diff --git a/src/EFCore.Design/Properties/DesignStrings.Designer.cs b/src/EFCore.Design/Properties/DesignStrings.Designer.cs index 1f43f910c25..83530118632 100644 --- a/src/EFCore.Design/Properties/DesignStrings.Designer.cs +++ b/src/EFCore.Design/Properties/DesignStrings.Designer.cs @@ -765,6 +765,12 @@ public static string WritingSnapshot(object? file) GetString("WritingSnapshot", nameof(file)), file); + /// + /// You cannot add a migration with the name 'Migration'. + /// + public static string CircularBaseClassDependency + => GetString("CircularBaseClassDependency"); + private static string GetString(string name, params string[] formatterNames) { var value = _resourceManager.GetString(name)!; diff --git a/src/EFCore.Design/Properties/DesignStrings.resx b/src/EFCore.Design/Properties/DesignStrings.resx index dd0ae2c93ce..44364bc6972 100644 --- a/src/EFCore.Design/Properties/DesignStrings.resx +++ b/src/EFCore.Design/Properties/DesignStrings.resx @@ -138,6 +138,9 @@ A type-qualified method call requires an instance identifier, a MethodInfo and no chained calls. + + You cannot add a migration with the name 'Migration'. + The entity type '{entityType}' has a custom constructor binding. This is usually caused by using proxies. Compiled model can't be generated, because dynamic proxy types are not supported. If you are not using proxies configure the custom constructor binding in '{customize}' in a partial '{className}' class instead. From c1f75ef2f65af0318d0c198b3edd0c9e5e843cec Mon Sep 17 00:00:00 2001 From: Kev Ritchie <65573253+KevRitchie@users.noreply.github.com> Date: Wed, 23 Feb 2022 14:52:42 +0000 Subject: [PATCH 3/3] Remove Migration Name Check from MigrationsAddCommand --- src/ef/Commands/MigrationsAddCommand.cs | 5 ----- src/ef/Properties/Resources.Designer.cs | 6 ------ src/ef/Properties/Resources.resx | 3 --- 3 files changed, 14 deletions(-) diff --git a/src/ef/Commands/MigrationsAddCommand.cs b/src/ef/Commands/MigrationsAddCommand.cs index 112244e3f8f..7a6da0e2505 100644 --- a/src/ef/Commands/MigrationsAddCommand.cs +++ b/src/ef/Commands/MigrationsAddCommand.cs @@ -14,11 +14,6 @@ protected override void Validate() { base.Validate(); - if (string.Equals(_name!.Value, "migration", StringComparison.OrdinalIgnoreCase)) - { - throw new CommandException(Resources.CircularBaseClassDependency); - } - if (string.IsNullOrEmpty(_name!.Value)) { throw new CommandException(Resources.MissingArgument(_name.Name)); diff --git a/src/ef/Properties/Resources.Designer.cs b/src/ef/Properties/Resources.Designer.cs index 5c8cee3bd02..9e7775be902 100644 --- a/src/ef/Properties/Resources.Designer.cs +++ b/src/ef/Properties/Resources.Designer.cs @@ -635,12 +635,6 @@ public static string WritingFile(object? file) GetString("WritingFile", nameof(file)), file); - /// - /// You cannot add a migration with the name 'Migration'. - /// - public static string CircularBaseClassDependency - => GetString("CircularBaseClassDependency"); - private static string GetString(string name, params string[] formatterNames) { var value = _resourceManager.GetString(name)!; diff --git a/src/ef/Properties/Resources.resx b/src/ef/Properties/Resources.resx index b893a40216b..d94a59d1fa5 100644 --- a/src/ef/Properties/Resources.resx +++ b/src/ef/Properties/Resources.resx @@ -402,7 +402,4 @@ Writing '{file}'... - - You cannot add a migration with the name 'Migration'. - \ No newline at end of file