diff --git a/src/EFCore.Jet/Migrations/Internal/JetHistoryRepository.cs b/src/EFCore.Jet/Migrations/Internal/JetHistoryRepository.cs index 6152dd2b..eabecf52 100644 --- a/src/EFCore.Jet/Migrations/Internal/JetHistoryRepository.cs +++ b/src/EFCore.Jet/Migrations/Internal/JetHistoryRepository.cs @@ -2,11 +2,14 @@ using System; using System.Text; +using EntityFrameworkCore.Jet.Internal; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Internal; using Microsoft.EntityFrameworkCore.Migrations; using EntityFrameworkCore.Jet.Utilities; +using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Storage; +using Microsoft.Extensions.DependencyInjection; namespace EntityFrameworkCore.Jet.Migrations.Internal { @@ -51,7 +54,7 @@ protected override string ExistsSql var builder = new StringBuilder(); builder - .Append("SHOW TABLES WHERE NAME=") + .Append("SELECT * FROM `INFORMATION_SCHEMA.TABLES` WHERE `TABLE_NAME` = ") .Append(stringTypeMapping.GenerateSqlLiteral(TableName)); return builder.ToString(); @@ -131,7 +134,7 @@ public override string GetCreateIfNotExistsScript() var stringTypeMapping = Dependencies.TypeMappingSource.GetMapping(typeof(string)); builder - .Append("IF NOT EXISTS (SELECT * FROM (SHOW TABLES) WHERE Name = ") + .Append("IF NOT EXISTS (SELECT * FROM `INFORMATION_SCHEMA.TABLES` WHERE `TABLE_NAME` = ") .Append(stringTypeMapping.GenerateSqlLiteral(TableName)) .Append(") THEN "); using (builder.Indent()) @@ -151,20 +154,7 @@ public override string GetCreateIfNotExistsScript() /// public override string GetBeginIfNotExistsScript(string migrationId) { - Check.NotEmpty(migrationId, nameof(migrationId)); - - var stringTypeMapping = Dependencies.TypeMappingSource.GetMapping(typeof(string)); - - return new StringBuilder() - .Append("IF NOT EXISTS(SELECT * FROM ") - .Append(SqlGenerationHelper.DelimitIdentifier(TableName)) - .Append(" WHERE ") - .Append(SqlGenerationHelper.DelimitIdentifier(MigrationIdColumnName)) - .Append(" = ") - .Append(stringTypeMapping.GenerateSqlLiteral(migrationId)) - .AppendLine(")") - .Append("THEN") - .ToString(); + throw new NotSupportedException(JetStrings.MigrationScriptGenerationNotSupported); } /// @@ -175,20 +165,7 @@ public override string GetBeginIfNotExistsScript(string migrationId) /// public override string GetBeginIfExistsScript(string migrationId) { - Check.NotEmpty(migrationId, nameof(migrationId)); - - var stringTypeMapping = Dependencies.TypeMappingSource.GetMapping(typeof(string)); - - return new StringBuilder() - .Append("IF EXISTS(SELECT * FROM ") - .Append(SqlGenerationHelper.DelimitIdentifier(TableName)) - .Append(" WHERE ") - .Append(SqlGenerationHelper.DelimitIdentifier(MigrationIdColumnName)) - .Append(" = ") - .Append(stringTypeMapping.GenerateSqlLiteral(migrationId)) - .AppendLine(")") - .Append("THEN") - .ToString(); + throw new NotSupportedException(JetStrings.MigrationScriptGenerationNotSupported); } /// @@ -197,6 +174,9 @@ public override string GetBeginIfExistsScript(string migrationId) /// 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. /// - public override string GetEndIfScript() => ";" + Environment.NewLine; + public override string GetEndIfScript() + { + throw new NotSupportedException(JetStrings.MigrationScriptGenerationNotSupported); + } } } \ No newline at end of file diff --git a/src/EFCore.Jet/Properties/JetStrings.Designer.cs b/src/EFCore.Jet/Properties/JetStrings.Designer.cs index 66a19350..de6bc298 100644 --- a/src/EFCore.Jet/Properties/JetStrings.Designer.cs +++ b/src/EFCore.Jet/Properties/JetStrings.Designer.cs @@ -20,6 +20,12 @@ public static class JetStrings { private static readonly ResourceManager _resourceManager = new ResourceManager("EntityFrameworkCore.Jet.Properties.JetStrings", typeof(JetStrings).GetTypeInfo().Assembly); + + /// + /// Generating idempotent scripts for migration is not currently supported by Jet. For more information, see http://go.microsoft.com/fwlink/?LinkId=723262. + /// + public static string MigrationScriptGenerationNotSupported + => GetString("MigrationScriptGenerationNotSupported"); /// /// Identity value generation cannot be used for the property '{property}' on entity type '{entityType}' because the property type is '{propertyType}'. Identity value generation can only be used with signed integer properties. diff --git a/src/EFCore.Jet/Properties/JetStrings.resx b/src/EFCore.Jet/Properties/JetStrings.resx index cd7df1ac..546f9d15 100644 --- a/src/EFCore.Jet/Properties/JetStrings.resx +++ b/src/EFCore.Jet/Properties/JetStrings.resx @@ -117,6 +117,9 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Generating idempotent scripts for migration is not currently supported by Jet. For more information, see https://github.com/bubibubi/EntityFrameworkCore.Jet/wiki. + Identity value generation cannot be used for the property '{property}' on entity type '{entityType}' because the property type is '{propertyType}'. Identity value generation can only be used with signed integer properties.