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

未关闭
#39,826 0 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

维护者通常 2 天内回复

@cincuranet 已经在做这个了。

开始于 2026年11月27日。

  • #39829 来自 @seragAhmed —— 未关闭

评估

难度
3/5
预计耗时
1-2 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
csharp, sqlite
领域
database

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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
主要语言
C#
星标
14.8k
派生
3.5k
平均合并
3 天 7 小时
30 天内合并 PR
182

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

dotnet/efcore 的其他 Issue

查看 dotnet/efcore 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。