SQLite: Polygon.Length translates to GLength, which returns 0

Đang mở
#39,826 0 bình luận 0 reaction 1 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

@cincuranet đang làm issue này rồi.

Từ ngày 27/11/2026.

  • #39829 của @seragAhmed — đang mở

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
csharp, sqlite
Lĩnh vực
database

Hướng nghiên cứu

Start in src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryMemberTranslator.cs and compare the Geometry.Length mapping with the provider behavior described here. Reproduce the square query using the supplied setup and check the SQLite spatial function used for polygon length. Done means the SQLite query returns the polygon perimeter, 16, consistently with NetTopologySuite; an open linked pull request indicates work is already underway.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

area-query area-sqlite

Description

With the SQLite NetTopologySuite provider, Polygon.Length is translated to GLength, which returns 0 for a polygon. NetTopologySuite returns the polygon's perimeter instead. For the 4×4 square below, the expected result is 16 but the query returns 0.

The SQLite provider's member translator maps Geometry.Length to GLength. The 11.0.0 translator uses the same mapping, although I have not run the repro against 11.0.0.

Related: npgsql/efcore.pg#4151 reports the same mismatch in the PostgreSQL provider's independent translation.

Reproduction

Create a .NET 10 console project with the following package references and install the native mod_spatialite library as described in the SQLite spatial documentation. The repro uses the system SQLite provider, as recommended there for macOS and Linux.

<ItemGroup>
  <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="10.0.15" />
  <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.NetTopologySuite" Version="10.0.15" />
  <PackageReference Include="SQLitePCLRaw.provider.sqlite3" Version="2.1.10" />
</ItemGroup>
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using NetTopologySuite.Geometries;

SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_sqlite3());
var factory = new GeometryFactory(new PrecisionModel(), 4326);
await using var context = new TestContext();
await context.Database.OpenConnectionAsync();
await context.Database.EnsureCreatedAsync();

var polygon = factory.CreatePolygon([new(0, 0), new(4, 0), new(4, 4), new(0, 4), new(0, 0)]);
context.Rows.Add(new Row { Polygon = polygon });
await context.SaveChangesAsync();

Console.WriteLine($"NTS: {polygon.Length}, SQLite: {await context.Rows.Select(r => r.Polygon.Length).SingleAsync()}");

public class TestContext : DbContext
{
    public DbSet<Row> Rows => Set<Row>();

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        => optionsBuilder
            .UseSqlite("Data Source=:memory:", o => o.UseNetTopologySuite())
            .LogTo(Console.WriteLine, LogLevel.Information);

    protected override void OnModelCreating(ModelBuilder modelBuilder)
        => modelBuilder.Entity<Row>().Property(r => r.Polygon).HasSrid(4326);
}

public class Row
{
    public int Id { get; set; }
    public Polygon Polygon { get; set; } = null!;
}

Output:

SELECT GLength("r"."Polygon")
FROM "Rows" AS "r"
LIMIT 2

NTS: 16, SQLite: 0

Environment

  • EF Core SQLite NetTopologySuite: 10.0.15
  • SpatiaLite: 5.1.0
  • .NET: 10.0.8
  • macOS arm64
Ngôn ngữ chính
C#
Star
14.8k
Fork
3.5k
Merge trung bình
3 ngày 7 giờ
Pull request đã merge (30 ngày)
182

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của dotnet/efcore

Tất cả issue của dotnet/efcore

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.