Skip to content

Commit 6ea053b

Browse files
Geography fix (#44)
* Fix tests. * Drop table. * another fix. * Fix tests * Default SRID. * Fix geography.
1 parent c1e99c1 commit 6ea053b

3 files changed

Lines changed: 29 additions & 19 deletions

File tree

src/PhenX.EntityFrameworkCore.BulkInsert.PostgreSql/PostgreSqlBulkInsertProvider.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ private static string GetBinaryImportCommand(IReadOnlyList<ColumnMetadata> prope
3535
{
3636
BatchSize = 50_000,
3737
Converters = [PostgreSqlGeometryConverter.Instance],
38-
TypeProviders = [PostgreSqlGeometryConverter.Instance],
3938
};
4039

4140
/// <inheritdoc />
Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
using Microsoft.EntityFrameworkCore.Metadata;
2-
31
using NetTopologySuite.Geometries;
42

5-
using NpgsqlTypes;
6-
73
using PhenX.EntityFrameworkCore.BulkInsert.Abstractions;
84
using PhenX.EntityFrameworkCore.BulkInsert.Options;
95

106
namespace PhenX.EntityFrameworkCore.BulkInsert.PostgreSql;
117

12-
internal sealed class PostgreSqlGeometryConverter : IBulkValueConverter, IPostgresTypeProvider
8+
internal sealed class PostgreSqlGeometryConverter : IBulkValueConverter
139
{
1410
public static readonly PostgreSqlGeometryConverter Instance = new();
1511

@@ -27,23 +23,11 @@ public bool TryConvertValue(object source, BulkInsertOptions options, out object
2723
geometry.SRID = options.SRID;
2824
}
2925

30-
result = geometry.ToBinary();
26+
result = geometry;
3127
return true;
3228
}
3329

3430
result = source;
3531
return false;
3632
}
37-
38-
public bool TryGetType(IProperty property, out NpgsqlDbType result)
39-
{
40-
if (property.ClrType.IsAssignableTo(typeof(Geometry)))
41-
{
42-
result = NpgsqlDbType.Bytea;
43-
return true;
44-
}
45-
46-
result = default;
47-
return false;
48-
}
4933
}

tests/PhenX.EntityFrameworkCore.BulkInsert.Tests/Tests/Geo/GeoTestsBase.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using FluentAssertions;
22

3+
using Microsoft.EntityFrameworkCore;
4+
35
using NetTopologySuite.Geometries;
46

57
using PhenX.EntityFrameworkCore.BulkInsert.Tests.DbContainer;
@@ -71,4 +73,29 @@ public async Task InsertEntities_WithGeo_And_Default_SRID(InsertStrategy strateg
7173
insertedEntities.Should().BeEquivalentTo(entities,
7274
o => o.RespectingRuntimeTypes().Excluding((TestEntityWithGeo e) => e.Id));
7375
}
76+
77+
[SkippableTheory]
78+
[CombinatorialData]
79+
public async Task InsertEntities_WithGeo_And_Search(InsertStrategy strategy)
80+
{
81+
// Arrange
82+
var runId = Guid.NewGuid();
83+
84+
var geo1 = new Point(1, 2) { SRID = 4326 };
85+
var geo2 = new Point(3, 4) { SRID = 4326 };
86+
87+
var entities = new List<TestEntityWithGeo>
88+
{
89+
new TestEntityWithGeo { TestRun = runId, GeoObject = geo1 },
90+
new TestEntityWithGeo { TestRun = runId, GeoObject = geo2 }
91+
};
92+
93+
// Act
94+
await _context.InsertWithStrategyAsync(strategy, entities);
95+
96+
var found = await _context.TestEntitiesWithGeo.Where(x => x.TestRun == runId && x.GeoObject.Distance(geo1) < 1).ToListAsync();
97+
98+
// Assert
99+
Assert.NotEmpty(found);
100+
}
74101
}

0 commit comments

Comments
 (0)