Skip to content

Commit

Permalink
MySql geometry fix
Browse files Browse the repository at this point in the history
  • Loading branch information
borisdj committed Jan 11, 2024
1 parent 337f4e8 commit 1289ab4
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion EFCore.BulkExtensions/SqlAdapters/MySql/MySqlAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ private static DataTable InnerGetDataTable<T>(DbContext context, ref Type type,

if (isMySql && (propertyType == typeof(Geometry) || propertyType.IsSubclassOf(typeof(Geometry))))
{
propertyType = typeof(byte[]);
propertyType = typeof(MySqlGeometry);
tableInfo.HasSpatialType = true;
if (tableInfo.BulkConfig.PropertiesToIncludeOnCompare != null || tableInfo.BulkConfig.PropertiesToIncludeOnCompare != null)
{
Expand Down Expand Up @@ -686,8 +686,16 @@ private static DataTable InnerGetDataTable<T>(DbContext context, ref Type type,
string columnName = tableInfo.ConvertiblePropertyColumnDict[property.Name];
propertyValue = tableInfo.ConvertibleColumnConverterDict[columnName].ConvertToProvider.Invoke(propertyValue);
}

//TODO: Hamdling special types

if (tableInfo.HasSpatialType && propertyValue is Geometry geometryValue)
{
geometryValue.SRID = tableInfo.BulkConfig.SRID;
var wkb = geometryValue.ToBinary();
propertyValue = MySqlGeometry.FromWkb(geometryValue.SRID, wkb);
}

if (propertyValue is HierarchyId hierarchyValue && isMySql)
{
using MemoryStream memStream = new();
Expand Down

0 comments on commit 1289ab4

Please sign in to comment.