Can Poyrazoğlu
Can Poyrazoğlu

Reputation: 34780

DbGeography is of a type that is invalid for use as a key column in an index or statistics

I am on Entity Framework 6.1 code first and I'm trying to create an index on a column of type DbGeography as my app is primarily location-focused so not indexing is not an option.

Here is the relevant part on my class:

public class Post
{
  ...
    [Required, Index(Order = 1)]
    public DateTime CreateDate { get; set; }

    [Required, Index(Order = 2)]
    public DbGeography Location { get; set; }
  ...
}

However when I run my app (I'm using SQL Azure) I get:

Column 'Location' in table 'dbo.Posts' is of a type that is invalid for use as a key column in an index or statistics.

How can I get rid of this problem without turning off spatial indexing?

Upvotes: 1

Views: 229

Answers (1)

Luis Bosquez
Luis Bosquez

Reputation: 386

Unfortunately, Spatial Types cannot be used as entity keys in Entity Framework since they work like Filtered Indexes. This post contains more information about using Spatial Types in the Entity Framework.

Upvotes: 1

Related Questions