Home > database >  How can I map an SQL Server geometry column to an EF6 property
How can I map an SQL Server geometry column to an EF6 property

Time:08-30

I have a nullable geography column in a table in a SQL Server database. In an Azure Function project (v4, .NET 6.08, NetTopologySuite included), when using Scaffold-DbContext to create an EF6 data context, the geometry column was mapped to Geometry? which seems right.

But when I run the project, and initialize the DBContext, I get the following error:

The property 'Geometry.UserData' could not be mapped because it is of type 'object', which is not a supported primitive type or a valid entity type.

BTW, I tried to change Geometry? to Point? but this made no difference.

What is going on? How can I map a Geography column to an EF6 property?

CodePudding user response:

You must configure the SQL Server provider options by enabling support for spatial type mappings with "UseNetTopologySuite":

options.UseSqlServer(
    @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=WideWorldImporters",
        x => x.UseNetTopologySuite());
  • Related