【发布时间】: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