如何使用 EF 6.1 fluent API 创建空间索引 [英] How to create spatial index using EF 6.1 fluent API

查看:14
本文介绍了如何使用 EF 6.1 fluent API 创建空间索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗯,这个问题已经很清楚了.是否可以使用 Entity Framework 6.1 fluent API 创建空间索引?

Well, the question is clear enough. Is it possible to create spatial indexes using Entity Framework 6.1 fluent API?

推荐答案

简答——不,不是.我在整个博客中都看到了这一点并且没有找到具体的实施例子.这似乎与空间索引是过滤索引的事实有关,实体框架不支持.

Short answer- No, it is not. I have seen this tangentially referenced throughout blogs and have found no concrete examples of implementation. It seems to be related to the fact that spatial indexes are filtered indexes, which are not supported in Entity Framework.

作为对我的回答的支持,我使用最新版本的 Entity Framework (6.1) 构建了一个 POC 控制台应用程序.我采取了以下步骤

As support for my answer I constructed a POC console app with the most recent version of Entity Framework (6.1). I took the following steps

  1. 创建了一个具有 DbGeography 类型属性的模型
  2. 启用自动迁移
  3. Ran Update-Database -verbose 确保运行添加索引的迁移.该索引使用以下内容:

  1. Created a model that had a property of the type DbGeography
  2. Enabled automatic migrations
  3. Ran Update-Database -verbose insuring migration with the addition of an index was run. The index used the following:

modelBuilder.Entity<LocationEntity>().Property(t => t.Coordinates).HasColumnAnnotation("Index", new IndexAnnotation(new IndexAttribute("ix_locationentity_coordinates")));

没有创建索引,但应用程序也没有崩溃.我可以尝试对此进行排列,但我的示例似乎遵循实体框架的约定:Fluent 官方文档

No indexes were created, but neither did the app crash. I could try permutations on this, but my example seems to follow the convention of entity framework: Official Fluent Documentation

这篇关于如何使用 EF 6.1 fluent API 创建空间索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆