Skip to content

Commit

Permalink
Fix for issue #25116 - Microsoft.EntityFrameworkCore.Sqlite.NetTopolo…
Browse files Browse the repository at this point in the history
…gySuite error during migration (#28476)

* fix for create temp table bug for spatial column (was missing TableName)

* build fix, forgot to add namespace using

Co-authored-by: Dmitry Grinblat <dmitry.grinblat@inovageo.com>
  • Loading branch information
d79ima and dgrinblat committed Jul 20, 2022
1 parent 2939c9e commit 8045443
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,8 @@ private IReadOnlyList<MigrationOperation> RewriteOperations(
ComputedColumnSql = column.ComputedColumnSql,
IsStored = column.IsStored,
Comment = column.Comment,
Collation = column.Collation
Collation = column.Collation,
Table = createTableOperation.Name
};
addColumnOperation.AddAnnotations(column.GetAnnotations());
createTableOperation.Columns.Add(addColumnOperation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.EntityFrameworkCore.Sqlite.Metadata.Internal;

namespace Microsoft.EntityFrameworkCore.Migrations;
using NetTopologySuite.Geometries;

public class SqliteMigrationsSqlGeneratorTest : MigrationsSqlGeneratorTestBase
{
Expand Down Expand Up @@ -968,6 +969,51 @@ public virtual void Deferred_AddColumn_defers_subsequent_CreateIndex()
");
}

[ConditionalFact]
public virtual void DropColumn_in_table_which_has_another_spatial_column()
{
Generate(
modelBuilder => modelBuilder.Entity(
"Blog",
x =>
{
x.Property<int>("Id");
x.Property<string>("Name");
x.Property<Geometry>("Position").HasColumnType("GEOMETRY").HasSrid(4326);
}),
migrationBuilder =>
{
migrationBuilder.DropColumn(
name: "Name",
table: "Blog");
});

AssertSql(
@"CREATE TABLE ""ef_temp_Blog"" (
""Id"" INTEGER NOT NULL CONSTRAINT ""PK_Blog"" PRIMARY KEY AUTOINCREMENT,
""Name"" TEXT NULL
);
SELECT AddGeometryColumn('ef_temp_Blog', 'Position', 4326, 'GEOMETRY', -1, 0);
GO
INSERT INTO ""ef_temp_Blog"" (""Id"", ""Name"", ""Position"")
SELECT ""Id"", ""Name"", ""Position""
FROM ""Blog"";
GO
PRAGMA foreign_keys = 0;
GO
DROP TABLE ""Blog"";
GO
ALTER TABLE ""ef_temp_Blog"" RENAME TO ""Blog"";
GO
PRAGMA foreign_keys = 1;
");
}

[ConditionalFact]
public virtual void RenameTable_preserves_pending_rebuilds()
{
Expand Down

0 comments on commit 8045443

Please sign in to comment.