如何使用EF Core中的点类型创建实体(安装了SQLite和Pasialite软件包)

发布于 2025-02-04 08:10:55 字数 549 浏览 3 评论 0原文

我将SQLITE与EF Core 6一起使用,然后安装了空间包装。我读了一份文档,说该文档说这种流利的API代码应该可以完成工作:

modelBuilder.Entity<City>().Property(c => c.Location)
    .HasSrid(4326);

但是我不知道如何编写位置属性的类型,因为没有可以定义的点类型,右键单击点类型不建议合适'使用'。

这是我要定义的实体:

public class City
{        
    public string Title { get; set; }
    public string Label { get; set; }
    public Point // right clicking recommends only: using System.Drawing and using Radzen.Blazor

}

在sqlite和ef core 6中: 如何为此点属性指定类型,以及Hassrid(4326)是否将列定义为点类型?

I use Sqlite with EF core 6, and I installed spatialite package. I read a documentation that says this fluent api code should do the job:

modelBuilder.Entity<City>().Property(c => c.Location)
    .HasSrid(4326);

But I don't know how to write the Location property's type, since there is no Point type that can be defined, And right clicking the Point type recommends no suitable 'using'.

This is the entity that I want to define:

public class City
{        
    public string Title { get; set; }
    public string Label { get; set; }
    public Point // right clicking recommends only: using System.Drawing and using Radzen.Blazor

}

In Sqlite and Ef core 6:
How to specify a type for this Point property and if the HasSrid(4326) defines the column as a Point type?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

决绝 2025-02-11 08:10:55

再通过一般阅读 EF Core中的Spaital数据and sqlite-spifific-noreforrer'>

除了安装Microsoft.entityframeworkcore.sqlite.nettopologysuite套件外,还需要在配置DBContext时调用usenettopologysuite

options.UseSqlite(
    connectionString,
    x => x.UseNetTopologySuite());

您要寻找的类型在 nettopologysuite.geometries 命名空间内。

呼叫hassrid(4326)表示您要使用WGS 84坐标系 - GPS通常使用的系统。

Have another read through the general Spaital data in EF Core article and the SQLite-specific one.

In addition to installing the Microsoft.EntityFrameworkCore.Sqlite.NetTopologySuite package, you need to call UseNetTopologySuite when configuring your DbContext.

options.UseSqlite(
    connectionString,
    x => x.UseNetTopologySuite());

The Point type you're looking for is inside the NetTopologySuite.Geometries namespace.

Calling HasSrid(4326) indicates that you want to use the WGS 84 coordinate system--the one typically used in GPS.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文