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

Error while diffing spatial seed data #18729

Closed
bricelam opened this issue Nov 2, 2019 · 13 comments
Closed

Error while diffing spatial seed data #18729

bricelam opened this issue Nov 2, 2019 · 13 comments
Assignees

Comments

@bricelam
Copy link
Contributor

bricelam commented Nov 2, 2019

Diffing the model snapshot against the original model in ModelSnapshotSqlServerTest.SeedData_annotations_are_stored_in_snapshot() results in the following exception.

System.ArgumentException: Operation does not support GeometryCollection arguments
   at NetTopologySuite.Geometries.Geometry.CheckNotGeometryCollection(Geometry g)
   at NetTopologySuite.Geometries.Geometry.Relate(Geometry g)
   at NetTopologySuite.Geometries.Geometry.EqualsTopologically(Geometry g)
   at Microsoft.EntityFrameworkCore.ChangeTracking.ValueComparer`1.Equals(T left, T right) in src\EFCore\ChangeTracking\ValueComparer`.cs:line 230
   at Microsoft.EntityFrameworkCore.ChangeTracking.ValueComparer`1.Equals(Object left, Object right) in src\EFCore\ChangeTracking\ValueComparer`.cs:line 212
   at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.DiffData(TableMapping source, TableMapping target, DiffContext diffContext) in src\EFCore.Relational\Migrations\Internal\MigrationsModelDiffer.cs:line 1811
   at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Diff(TableMapping source, TableMapping target, DiffContext diffContext)+MoveNext() in src\EFCore.Relational\Migrations\Internal\MigrationsModelDiffer.cs:line 605
   at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.DiffCollection[T](IEnumerable`1 sources, IEnumerable`1 targets, DiffContext diffContext, Func`4 diff, Func`3 add, Func`3 remove, Func`4[] predicates)+MoveNext() in src\EFCore.Relational\Migrations\Internal\MigrationsModelDiffer.cs:line 2097
   at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
   at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Sort(IEnumerable`1 operations, DiffContext diffContext) in src\EFCore.Relational\Migrations\Internal\MigrationsModelDiffer.cs:line 189
   at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.GetDifferences(IModel source, IModel target) in src\EFCore.Relational\Migrations\Internal\MigrationsModelDiffer.cs:line 153
   at Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest.Test(IModel model, String expectedCode, Action`2 assert) in test\EFCore.Design.Tests\Migrations\ModelSnapshotSqlServerTest.cs:line 3749
   at Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest.Test(Action`1 buildModel, String expectedCode, Action`2 assert) in test\EFCore.Design.Tests\Migrations\ModelSnapshotSqlServerTest.cs:line 3673
   at Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest.SeedData_annotations_are_stored_in_snapshot() in test\EFCore.Design.Tests\Migrations\ModelSnapshotSqlServerTest.cs:line 3174
@bricelam
Copy link
Contributor Author

Possibly external (NetTopologySuite/NetTopologySuite#213)

@roji
Copy link
Member

roji commented May 29, 2020

Didn't we switch to EqualsExact for query translation? We may want to do the same for the value comparer...

@bricelam
Copy link
Contributor Author

This may have been fixed by that change. I didn’t try reproing again

@roji
Copy link
Member

roji commented May 29, 2020

Sorry, I wrote some nonsense - #18946 did change GeometryValueComparer to use EqualsExact instead of EqualsTopologically; this is in 5.0.0-preview1. So there's a very good chance this is just a dup of #18921.

@OskarKlintrot
Copy link

I seem to get this on SaveChanges as well:

System.ArgumentException:
   at NetTopologySuite.Geometries.Geometry.CheckNotGeometryCollection (NetTopologySuite, Version=2.0.0.0, Culture=neutral, PublicKeyToken=f580a05016ebada1)
   at NetTopologySuite.Geometries.Geometry.Relate (NetTopologySuite, Version=2.0.0.0, Culture=neutral, PublicKeyToken=f580a05016ebada1)
   at NetTopologySuite.Geometries.Geometry.EqualsTopologically (NetTopologySuite, Version=2.0.0.0, Culture=neutral, PublicKeyToken=f580a05016ebada1)
   at lambda_method (Anonymously Hosted DynamicMethods Assembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null)
   at Microsoft.EntityFrameworkCore.ChangeTracking.ValueComparer`1.Equals (Microsoft.EntityFrameworkCore, Version=3.1.4.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
   at Microsoft.EntityFrameworkCore.ChangeTracking.ValueComparer`1.Equals (Microsoft.EntityFrameworkCore, Version=3.1.4.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.LocalDetectChanges (Microsoft.EntityFrameworkCore, Version=3.1.4.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.DetectChanges (Microsoft.EntityFrameworkCore, Version=3.1.4.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
   at Microsoft.EntityFrameworkCore.ChangeTracking.ChangeTracker.DetectChanges (Microsoft.EntityFrameworkCore, Version=3.1.4.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
   at Microsoft.EntityFrameworkCore.DbContext.TryDetectChanges (Microsoft.EntityFrameworkCore, Version=3.1.4.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
   at Microsoft.EntityFrameworkCore.DbContext+<SaveChangesAsync>d__54.MoveNext (Microsoft.EntityFrameworkCore, Version=3.1.4.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)

@OskarKlintrot
Copy link

OskarKlintrot commented Jun 3, 2020

I tried to upgrade to 5-preview4 and the issue seems to be resolved there. Is there any workaround for EF Core 3? Not sure I want to use a preview version in production...

@roji
Copy link
Member

roji commented Jun 3, 2020

@OskarKlintrot you can copy GeometryValueComparer.cs and make the switch to EqualsExact just like #18946 did. See these docs about value comparers.

@OskarKlintrot
Copy link

@roji Thanks, that shouldn't be any problem! I where just looking through the source code instead of the docs to see how to get it working, I followed the new GeometryValueComparer() up to SqlServerNetTopologySuiteTypeMappingSourcePlugin but that seemed a bit overkill to replace :)

@roji
Copy link
Member

roji commented Jun 3, 2020

@OskarKlintrot yep, you shouldn't need to do anything with the plugin - just configure the modified value comparer on the spatial properties where this is a problem.

@OskarKlintrot
Copy link

@roji Looks like it's working now! It didn't work for the InMemory-db though ("fixed" it with Database.IsSqlServer()). I keep forgetting how modular and customizable EF Core actually is!

@ajcvickers
Copy link
Member

Given this discussion it seems this could be a duplicate of #18921 ans is therefore likely fixed.

@ajcvickers ajcvickers removed this from the 5.0.0 milestone Jun 3, 2020
@roji
Copy link
Member

roji commented Jun 3, 2020

Confirmed, repro'd the bug on 3.1.4, and it's gone in 5.0.0-preview4.

Repro
class Program
{
    static async Task Main(string[] args)
    {
        await using var ctx = new BlogContext();
        await ctx.Database.EnsureDeletedAsync();
        await ctx.Database.EnsureCreatedAsync();
    }
}

public class BlogContext : DbContext
{
    public DbSet<Blog> Blogs { get; set; }

    static ILoggerFactory ContextLoggerFactory
        => LoggerFactory.Create(b => b.AddConsole().AddFilter("", LogLevel.Information));

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        => optionsBuilder
            .UseNpgsql(@"Host=localhost;Username=test;Password=test", o => o.UseNetTopologySuite())
            .EnableSensitiveDataLogging()
            .UseLoggerFactory(ContextLoggerFactory);

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.HasPostgresExtension("postgis");

        modelBuilder.Entity<Blog>().HasData(new Blog
        {
            Id = 1,
            SomeGeometry = new GeometryCollection(new[] { new Point(1, 1) })
        });
    }
}

public class Blog
{
    public int Id { get; set; }
    public Geometry SomeGeometry { get; set; }
}

@roji
Copy link
Member

roji commented Jun 3, 2020

Duplicate of #18921

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants