Ima*_*tas 7 c# sql-server sqlgeography nettopologysuite entity-framework-core
我正在使用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}));
}
}
Run Code Online (Sandbox Code Playgroud)
EF核心在生成迁移时处理得很好,从而生成以下代码:
migrationBuilder.CreateIndex(
name: "IX_Locations_Coordinates",
schema: "data",
table: "Locations",
column: "Coordinates");
Run Code Online (Sandbox Code Playgroud)
但是,只要我尝试将迁移应用到数据库,SqlException就会抛出以下消息
SqlException:表'data.Locations'中的列'Coordinates'的类型无效,无法用作索引或统计信息中的键列.
SQL Server的确实对类型的列支持索引geography.
我相信原因可能是EF Core试图创建一个常规索引而不是空间索引.
我做错了什么还是不支持?有没有办法告诉EF Core它应该创建空间索引?
查看EF Core的问题日志,似乎尚不支持创建空间索引.
https://github.com/aspnet/EntityFrameworkCore/issues/12538
问题1100是支持SQL Server和SQL Lite上的空间数据类型.
| 归档时间: |
|
| 查看次数: |
249 次 |
| 最近记录: |