【问题标题】:What is the equivalent of DbGeography in EF core?EF 核心中的 DbGeography 等价物是什么?
【发布时间】:2021-09-20 07:54:33
【问题描述】:

EF 核心中的 DbGeography 等价物是什么?
我想将以下代码从 EF 转换为 EF Core:

using System.Data.Entity.Spatial;

namespace Domain
{
    public class City
    {
        public int CityId { get; set; }
        
        public DbGeography Coordinates { get; set; }
    }
}

【问题讨论】:

    标签: c# .net-core entity-framework-core spatial


    【解决方案1】:

    您必须将 NetTopologySuite 与 EF Core 一起使用,并且有一个库列表可以为特定的数据提供者启用它:https://docs.microsoft.com/en-us/ef/core/modeling/spatial

    【讨论】:

      【解决方案2】:

      为了在 EF Core 中使用空间数据,我们需要安装相应的支持 NuGet 包。
      例如 Microsoft.EntityFrameworkCore.SqlServer 的 Spatial NuGet 包是 Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite
      然后我们可以使用这个空间类型:

      • 几何
      • 线串
      • 多边形
      • 几何集合
      • 多点
      • 多行字符串
      • 多多边形

      默认情况下,空间属性映射到 SQL Server 中的地理列。
      要使用几何,我们在模型中配置列类型。

      【讨论】:

        猜你喜欢
        • 2019-07-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-04-27
        • 2011-01-29
        • 1970-01-01
        • 1970-01-01
        • 2014-05-08
        相关资源
        最近更新 更多