【问题标题】:Is there a way to declare a Spatial Index with EntityFrameworkCore 2.2?有没有办法使用 EntityFrameworkCore 2.2 声明空间索引?
【发布时间】:2019-01-30 09:00:17
【问题描述】:

我将 Entity Framework Core 2.2 与 NetTopologySuite 1.15.1 和 SQL Server 2016 一起使用。拥有IPoint 类型的列非常有用,以至于我想在其上创建索引。

我有这张桌子

public class Location
{
    public int Id { get; set; }

    public IPoint Coordinates { get; set; }

    public static void Register(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Location>(entity => entity.HasIndex(x => new {x.Coordinates}));
    }
}

EF 核心在生成迁移时很好地处理它,从而生成以下代码:

migrationBuilder.CreateIndex(
    name: "IX_Locations_Coordinates",
    schema: "data",
    table: "Locations",
    column: "Coordinates");

但是,一旦我尝试将迁移应用到数据库,SqlException 就会抛出以下消息

SqlException:表 'data.Locations' 中的列 'Coordinates' 的类型不能用作索引或统计信息中的键列。

SQL Server是否支持geography 类型列的索引。

我认为原因可能是 EF Core 试图创建 regular index 而不是 spatial one。

是我做错了什么还是不支持?有没有办法告诉 EF Core 它应该创建空间索引?

【问题讨论】:

    标签: c# sql-server entity-framework-core sqlgeography nettopologysuite


    【解决方案1】:

    查看 EF Core 的问题日志,似乎尚不支持创建空间索引。

    https://github.com/aspnet/EntityFrameworkCore/issues/12538

    问题1100 是在 SQL Server 和 SQL Lite 上支持空间数据类型。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-10
      • 1970-01-01
      • 1970-01-01
      • 2020-09-29
      • 1970-01-01
      • 2012-01-02
      • 1970-01-01
      • 2021-05-10
      相关资源
      最近更新 更多