From 6da6f69e7acc74fb72738c08518fe822b0f0db83 Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Sat, 16 Nov 2019 12:24:25 -0800 Subject: [PATCH] Switch to using EqualsExact in geometry comparer Fixes #18921 --- .../ChangeTracking/GeometryValueComparer.cs | 2 +- .../RelationalGeometryTypeMappingTest.cs | 57 +++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 test/EFCore.Relational.Tests/Storage/RelationalGeometryTypeMappingTest.cs diff --git a/src/EFCore/ChangeTracking/GeometryValueComparer.cs b/src/EFCore/ChangeTracking/GeometryValueComparer.cs index 1453fd7e6e7..10c5a635524 100644 --- a/src/EFCore/ChangeTracking/GeometryValueComparer.cs +++ b/src/EFCore/ChangeTracking/GeometryValueComparer.cs @@ -31,7 +31,7 @@ private static Expression> GetEqualsExpression( return Expression.Lambda>( Expression.Call( left, - typeof(TGeometry).GetRuntimeMethod("EqualsTopologically", new[] { typeof(TGeometry) }), + typeof(TGeometry).GetRuntimeMethod("EqualsExact", new[] { typeof(TGeometry) }), right), left, right); diff --git a/test/EFCore.Relational.Tests/Storage/RelationalGeometryTypeMappingTest.cs b/test/EFCore.Relational.Tests/Storage/RelationalGeometryTypeMappingTest.cs new file mode 100644 index 00000000000..4ca3925bcb0 --- /dev/null +++ b/test/EFCore.Relational.Tests/Storage/RelationalGeometryTypeMappingTest.cs @@ -0,0 +1,57 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using NetTopologySuite.Geometries; +using Xunit; + +namespace Microsoft.EntityFrameworkCore.Storage +{ + public class RelationalGeometryTypeMappingTest + { + [ConditionalFact] + public void Comparer_uses_exact_comparison() + { + var geometry1 = new GeometryCollection(new[] + { + new Point(1, 2), + new Point(3, 4) + }); + var geometry2 = new GeometryCollection(new[] + { + new Point(3, 4), + new Point(1, 2) + }); + + var comparer = new FakeRelationalGeometryTypeMapping().Comparer; + Assert.False(comparer.Equals(geometry1, geometry2)); + } + + private class FakeRelationalGeometryTypeMapping : RelationalGeometryTypeMapping + { + public FakeRelationalGeometryTypeMapping() + : base(new NullValueConverter(), "geometry") + { + } + + private FakeRelationalGeometryTypeMapping(RelationalTypeMappingParameters parameters) + : base(parameters, new NullValueConverter()) + { + } + + protected override RelationalTypeMapping Clone(RelationalTypeMappingParameters parameters) + => new FakeRelationalGeometryTypeMapping(parameters); + + protected override Type WKTReaderType { get; } + protected override string AsText(object value) => throw new NotImplementedException(); + protected override int GetSrid(object value) => throw new NotImplementedException(); + + class NullValueConverter : ValueConverter + { + public NullValueConverter() : base(t => t, t => t) {} + } + } + + } +}