代码之家  ›  专栏  ›  技术社区  ›  Imantas

有没有方法用EntityFrameworkCore2.2声明空间索引?

  •  5
  • Imantas  · 技术社区  · 6 年前

    我正在使用 实体框架核心2.2 具有 网络拓扑套件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 core在生成迁移时处理得很好,因此生成以下代码:

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

    但是,一旦我尝试将迁移应用到数据库, SqlException 与以下消息一起引发

    SqlException:表“data.locations”中的列“coordinates”的类型不能用作索引或统计信息中的键列。

    SQL Server 支持类型的列上的索引 geography .

    我相信原因可能是英孚核心试图创造一个 regular index 而不是 spatial one .

    是我做错了什么,还是只是不受支持?有没有办法告诉英孚核心应该创建空间索引?

    1 回复  |  直到 6 年前
        1
  •  4
  •   codingbadger    6 年前

    查看ef core的问题日志,似乎还不支持创建空间索引。

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

    github

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