Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code-first spatial index creation #26

Open
jamesra opened this issue Apr 6, 2022 · 4 comments
Open

Code-first spatial index creation #26

jamesra opened this issue Apr 6, 2022 · 4 comments

Comments

@jamesra
Copy link

jamesra commented Apr 6, 2022

I am getting this error creating my database from scratch in a unit test:

Microsoft.Data.SqlClient.SqlException: 'Column 'MosaicShape' in table 'Location' is of a type that is invalid for use as a key column in an index or statistics.'

This is a simplified version of the class. It was reverse-engineered by EF Core Power Tools.

[Table("Location")]
[Index(nameof(MosaicShape), Name = "MosaicShape_Index")]
class Location{

 [Key]
 [Column("ID")]
 public long Id { get; set; }

 [Required]
 [Column(TypeName = "geometry")]
 public Geometry MosaicShape { get; set; }
} 

In a unit test I attempt to create this database from scratch. The error occurs at DataContext.Database.EnsureCreated();

public CreateDropDatabaseFixture(IConfiguration configuration, ILogger log = null)
{
    var connStringTemplate = configuration.GetConnectionString("AnnotationConnection");

    DatabaseName = RandomLetters(6);
    var connString = string.Format(connStringTemplate, DatabaseName);

    DbContextOptionsBuilder<AnnotationContext> builder = new DbContextOptionsBuilder<AnnotationContext>();
    builder = builder.UseSqlServer(connString, config => config.UseNetTopologySuite()).EnableDetailedErrors().EnableSensitiveDataLogging();
    DataContext = new AnnotationContext(builder.Options, log);
     
    DataContext.Database.EnsureCreated();
}

This previous issue indicates a spatial index should be possible. dotnet/efcore#12538

I also tried removing the [Index] attribute from the class and creating it with the builder:

entity.HasIndex(e => e.MosaicShape, "MosaicShape_Index");

The error was the same, as expected.

@airbreather
Copy link
Member

Microsoft.Data.SqlClient.SqlException: 'Column 'MosaicShape' in table 'Location' is of a type that is invalid for use as a key column in an index or statistics.'

This error looks significantly different from what's in this issue's title. Can you please update one or the other, or add details about how the Geometry.UserData error fits into it?

@jamesra jamesra changed the title Geometry.UserData could not be mapped when creating a reverse engineered code-first database. Code-first spatial index creation Apr 6, 2022
@jamesra
Copy link
Author

jamesra commented Apr 6, 2022

Sorry about that. I had another issue I solved before filing this one. I also mis-keyed and submitted this a bit early, but I'm still struggling with it so I left it submitted.

@bricelam
Copy link
Collaborator

Are you looking for dotnet/efcore#12538?

@jamesra
Copy link
Author

jamesra commented Apr 18, 2022

Yes, apparently I am.

@FObermaier FObermaier transferred this issue from NetTopologySuite/NetTopologySuite Apr 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants