问题描述
嗯,问题很清楚。使用Entity Framework 6.1流畅的API可以创建空间索引?简答案 - 否, 不是这样。我在中已经看到了这一切并没有发现具体的实施实例。这似乎与空间索引是过滤索引的事实有关,实体框架不支持这些索引。
作为对我答案的支持,我构建了一个最新版本的Entity Framework(6.1)的POC控制台应用程序。我采取了以下步骤
- 创建了一个具有DbGeography类型的属性的模型
- 已启用自动迁移
-
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
- Created a model that had a property of the type DbGeography
- Enabled automatic migrations
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创建空间索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!