Skip to content

Commit

Permalink
Update to EF Core 8.0.1 (PomeloFoundation#1852)
Browse files Browse the repository at this point in the history
* Update dependencies.

* Update tests for EF Core 8.0.1.

* Fix NTS source type mappings.

* Implement MySqlRuntimeModelConvention and MySqlCSharpRuntimeAnnotationCodeGenerator. Update model extension methods.

* Fix identity columns.

* Improve test utilities.

* Refactor MySqlParameterInliningExpressionVisitor.

* Adjust TransactionMySqlTest.

* Ensure different default database names for Northwind databases with different collations.

* Correct MySqlBug96947Workaround version range.
  • Loading branch information
lauxjpn authored Feb 27, 2024
1 parent cdcaeac commit 3ef628f
Show file tree
Hide file tree
Showing 25 changed files with 1,047 additions and 206 deletions.
10 changes: 5 additions & 5 deletions Dependencies.targets
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup Label="Common Versions">
<EFCoreVersion>[8.0.0,8.0.999]</EFCoreVersion>
<EFCoreVersion>[8.0.1,8.0.999]</EFCoreVersion>
</PropertyGroup>

<ItemGroup Label="Dependencies">
Expand All @@ -13,16 +13,16 @@
<PackageReference Update="MySqlConnector.DependencyInjection" Version="2.3.5" />

<PackageReference Update="NetTopologySuite" Version="2.5.0" />
<PackageReference Update="System.Text.Json" Version="8.0.0" />
<PackageReference Update="System.Text.Json" Version="8.0.1" />
<PackageReference Update="Newtonsoft.Json" Version="13.0.3" />

<PackageReference Update="Castle.Core" Version="5.1.1" />
<PackageReference Update="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Update="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.0" />
<PackageReference Update="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.1" />
<PackageReference Update="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.1" />
<PackageReference Update="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" />
<PackageReference Update="Microsoft.Bcl.HashCode" Version="1.1.1" />
<PackageReference Update="Microsoft.Extensions.Caching.Memory" Version="8.0.0" />
<PackageReference Update="Microsoft.Extensions.Configuration.Binder" Version="8.0.0" />
<PackageReference Update="Microsoft.Extensions.Configuration.Binder" Version="8.0.1" />
<PackageReference Update="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
<PackageReference Update="Microsoft.Extensions.Configuration.FileExtensions" Version="8.0.0" />
<PackageReference Update="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
Expand Down
2 changes: 1 addition & 1 deletion dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"dotnet-ef": {
"version": "8.0.0",
"version": "8.0.1",
"commands": [
"dotnet-ef"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method
_sqlExpressionFactory.Constant(1))
},
method.ReturnType,
_typeMappingSource.FindMapping(method.ReturnType, storeType),
_typeMappingSource.FindMapping(method.ReturnType),
false);
}

Expand All @@ -137,7 +137,7 @@ public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method
instance,
arguments[0],
method.ReturnType,
_typeMappingSource.FindMapping(method.ReturnType, storeType));
_typeMappingSource.FindMapping(method.ReturnType));
}

if (Equals(method, _isWithinDistance))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,6 @@ public class MySqlNetTopologySuiteTypeMappingSourcePlugin : IRelationalTypeMappi
{ "multipolygon", typeof(MultiPolygon) }, // geometry -> geometrycollection -> multisurface -> multipolygon
};

private static readonly Dictionary<Type, string> _spatialClrTypeMappings = new Dictionary<Type, string>
{
{ typeof(Geometry), "geometry" }, // geometry
{ typeof(Point), "point" }, // geometry -> point
{ typeof(LineString), "linestring" }, // geometry -> curve -> linestring
{ typeof(LinearRing), "linearring" }, // geometry -> curve -> linestring -> linearring
{ typeof(Polygon), "polygon" }, // geometry -> surface -> polygon
{ typeof(GeometryCollection), "geometrycollection" }, // geometry -> geometrycollection
{ typeof(MultiPoint), "multipoint" }, // geometry -> geometrycollection -> multipoint
{ typeof(MultiLineString), "multilinestring" }, // geometry -> geometrycollection -> multicurve -> multilinestring
{ typeof(MultiPolygon), "multipolygon" }, // geometry -> geometrycollection -> multisurface -> multipolygon
};

private readonly NtsGeometryServices _geometryServices;
private readonly IMySqlOptions _options;

Expand Down Expand Up @@ -89,72 +76,75 @@ public MySqlNetTopologySuiteTypeMappingSourcePlugin(
public virtual RelationalTypeMapping FindMapping(in RelationalTypeMappingInfo mappingInfo)
{
var clrType = mappingInfo.ClrType;
var storeTypeName = mappingInfo.StoreTypeName;
var storeTypeNameBase = mappingInfo.StoreTypeNameBase;
var storeTypeName = mappingInfo.StoreTypeName?.ToLowerInvariant();
string defaultStoreType = null;
Type defaultClrType = null;

return (clrType != null
&& TryGetDefaultStoreType(clrType, out defaultStoreType))
|| (storeTypeName != null
&& _spatialStoreTypeMappings.TryGetValue(storeTypeName, out defaultClrType))
? (RelationalTypeMapping)Activator.CreateInstance(
typeof(MySqlGeometryTypeMapping<>).MakeGenericType(clrType ?? defaultClrType ?? typeof(Geometry)),
_geometryServices,
storeTypeName ?? defaultStoreType ?? "geometry",
_options)
: null;
}

if (storeTypeName != null)
private static bool TryGetDefaultStoreType(Type type, out string defaultStoreType)
{
// geometry -> geometrycollection -> multisurface -> multipolygon
if (typeof(MultiPolygon).IsAssignableFrom(type))
{
// First look for the fully qualified store type name.
if (_spatialStoreTypeMappings.TryGetValue(storeTypeName, out var mappedClrType))
{
// We found the user-specified store type.
// If no CLR type was provided, we're probably scaffolding from an existing database. Take the first
// mapping as the default.
// If a CLR type was provided, look for a mapping between the store and CLR types. If none is found,
// fail immediately.
clrType = clrType == null
? mappedClrType
: clrType.IsAssignableFrom(mappedClrType)
? clrType
: null;

return clrType == null
? null
: (RelationalTypeMapping)Activator.CreateInstance(
typeof(MySqlGeometryTypeMapping<>).MakeGenericType(clrType),
_geometryServices,
storeTypeName,
_options);
}

// Then look for the base store type name.
if (_spatialStoreTypeMappings.TryGetValue(storeTypeNameBase, out mappedClrType))
{
clrType = clrType == null
? mappedClrType
: clrType.IsAssignableFrom(mappedClrType)
? clrType
: null;

if (clrType == null)
{
return null;
}

var typeMapping = (RelationalTypeMapping)Activator.CreateInstance(
typeof(MySqlGeometryTypeMapping<>).MakeGenericType(clrType),
_geometryServices,
storeTypeName,
_options);

return typeMapping.Clone(mappingInfo);
}

// A store type name was provided, but is unknown. This could be a domain (alias) type, in which case
// we proceed with a CLR type lookup (if the type doesn't exist at all the failure will come later).
defaultStoreType = "multipolygon";
}

if (clrType != null &&
_spatialClrTypeMappings.TryGetValue(clrType, out var mappedStoreTypeName))
// geometry -> geometrycollection -> multicurve -> multilinestring
else if (typeof(MultiLineString).IsAssignableFrom(type))
{
return (RelationalTypeMapping)Activator.CreateInstance(
typeof(MySqlGeometryTypeMapping<>).MakeGenericType(clrType),
_geometryServices,
mappedStoreTypeName,
_options);
defaultStoreType = "multilinestring";
}
// geometry -> geometrycollection -> multipoint
else if (typeof(MultiPoint).IsAssignableFrom(type))
{
defaultStoreType = "multipoint";
}
// geometry -> geometrycollection
else if (typeof(GeometryCollection).IsAssignableFrom(type))
{
defaultStoreType = "geometrycollection";
}
// geometry -> surface -> polygon
else if (typeof(Polygon).IsAssignableFrom(type))
{
defaultStoreType = "polygon";
}
// geometry -> curve -> linestring -> linearring
else if (typeof(LinearRing).IsAssignableFrom(type))
{
defaultStoreType = "linearring";
}
// geometry -> curve -> linestring
else if (typeof(LineString).IsAssignableFrom(type))
{
defaultStoreType = "linestring";
}
// geometry -> point
else if (typeof(Point).IsAssignableFrom(type))
{
defaultStoreType = "point";
}
// geometry
else if (typeof(Geometry).IsAssignableFrom(type))
{
defaultStoreType = "geometry";
}
else
{
defaultStoreType = null;
}

return null;
return defaultStoreType != null;
}
}
}
Loading

0 comments on commit 3ef628f

Please sign in to comment.