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

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

问题描述

嗯,问题很清楚。使用Entity Framework 6.1流畅的API可以创建空间索引

解决方案

简答案 - 否, 不是这样。我在博客中已经看到了这一切并没有发现具体的实施实例。这似乎与空间索引是过滤索引的事实有关,实体框架不支持这些索引。



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


  1. 创建了一个具有DbGeography类型的属性的模型

  2. 已启用自动迁移

  3. Ran Update - 运行添加索引的数据库 - 保证迁移。该索引使用以下内容:



    modelBuilder.Entity< LocationEntity>()。属性(t => t.Coordinates).HasColumnAnnotation(索引,新的IndexAnnotation(新的IndexAttribute(ix_locationentity_coordinates)));




<没有创建索引,但是应用程序也没有崩溃。我可以尝试排列这个,但我的例子似乎遵循实体框架的惯例:官方流利文件


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.

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. 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")));

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流畅的API创建空间索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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