This topic is applicable to Entity Framework v5 and v6. For Entity Framework Core, see Spatial Data Support for EF Core.
In MySQL, the geometry data type is used to represent spatials. Entity Framework 5 uses DbGeometry and DbGeography types from the System.Data.Entity.dll assembly for this purpose (.NET Framework 4.5). Entity Framework 6 uses DbGeometry and DbGeography types from the EntityFramework.dll (.NET Framework 4.0 and .NET Framework 4.5).
When using XML mapping spatial types are mapped in the following way in edmx/edml files:
MySQL data types | SSDL | CSDL | .NET |
---|---|---|---|
geometry | spatial_geometry | Geometry, GeometryCollection, GeometryLineString, GeometryMultiLineString, GeometryMultiPoint, GeometryMultiPolygon, GeometryPoint, GeometryPolygon | DbGeometry |
geometry | spatial_geography | Geography, GeographyCollection, GeographyLineString, GeographyMultiLineString, GeographyMultiPoint, GeographyMultiPolygon, GeographyPoint, GeographyPolygon | DbGeography |
When creating Entity Framework model in Entity Data Model Wizard or LightSwitch Attach Data Source Wizard using Database First approach, all spatial columns are mapped to DbGeometry, and it is impossible to change this behaviour currently. If you need to map properties to DbGeography, open the Entity Framework model with XML editor and replace data type for the required columns: "spatial_geometry" with "spatial_geography" in SSDL and "Geometry" with "Geography" in CSDL. When creating an Entity Framework model in Devart Entity Developer using Database First approach, you can define corresponding data type mapping rules.