Search code examples
c#mysqlentity-frameworkspatialconnector-net

MySQL Connector/Net EF Database First Spatial Datatypes


Using:

  • Entity Framework 5
  • MySQL Connector Net 6.8.4
  • MySQL 5.6.21
  • Visual Studio 2013
  • MySQL Workbench 6.2

Created the following table in MySQL using the workbench MySQL table, five columns of types int as pk, linestring, polygon, double, geometry

Opened my application in Visual Studio 2013, navigated to my data access layer project, opened the .edmx, right-clicked on the canvas and chose "Update model from database...". I proceeded to add the new table, clicked finish, and this is what got spit out:

Route Geometry db model table with not the correct properties Redundant picture of auto-generated model class

As you can see all the spatial data types were just ignored.

The Data Access project include (among other things) the following references:

  • EntityFramework
  • MySql.Data
  • MySql.Data.Entity.EF5
  • MySql.Web
  • System.Data.Entity

I realize that in EF they'll be of type DbGeometry, but I feel like the update process should be able to figure this out for itself. And while I could manually add the mappings, I would prefer not to since they would get blown away next time someone runs the "Update model from database..."

Any insights or suggestions? Thanks!

Edit: Tested with Entity Framework 6 and continued to have the issue


Solution

  • Looking at the Error List Warnings after attempting an "Update Model from Database" I now see:

    Error 6005: The data type 'geometry' is currently not supported for the target Entity Framework version; the column 'test_geometry' in the table 'def.spatialdb.routegeometry' was excluded.

    This is using latest Entity Framework 6, so I guess it's not possible using code-first only.

    Possible solution would be to edit the auto-generated classes to add the DBGeometry properties, but those would get blown away every time the model is updated.