-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Open
Description
Bug description
Context
- Windows 11
- SQL Server 2017
- EF Core 8.0.18 (I also tried on .NET 10 and EF Core 10.0.1, and same issue)
Problem
I build a NTS Geometry object and assign it to an object's field, which is then persisted to a table using EF Core.
The record is stored in the database properly, but when I do:
SELECT Geography.STIsValid() FROM MyTable
It returns 0
The issue only happens with certain shapes (the attached one is an example)
Your code
class MyTable
{
public int Id { get; set; }
public Geometry? Geography { get; set; }
}
class MyDBContext : DbContext
{
public DbSet<MyTable> MyTable { get; set; }
public MyDBContext(DbContextOptions<MyDBContext> options) : base(options)
{
}
}
[Test]
public void TestDodgyGeography()
{
var options = new DbContextOptionsBuilder<MyDBContext>()
.UseSqlServer("Data Source=localhost;Initial Catalog=MyDB;User ID=sa;Password=Pass1234;Trust Server Certificate=true", x => x.UseNetTopologySuite())
.Options;
var context = new MyDBContext(options);
var geo = new WKTReader(new NtsGeometryServices(PrecisionModel.Floating.Value, 4269)).Read("MY MULTIPOLYGON IS TOO BIG SO I HAVE ADDED IT AS AN ATTACHMENT");
context.MyTable.Add(new MyTable { Id = 1, Geography = geo });
context.SaveChanges();
}Stack traces
Verbose output
EF Core version
8.0.18
Database provider
Microsoft.EntityFrameworkCore.SqlServer
Target framework
.NET 8
Operating system
Windows 11
IDE
No response