Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to EF Core 6.0.0-rc1 #1531

Merged
merged 14 commits into from
Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Dependencies.targets
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project>
<PropertyGroup Label="Common Versions">
<DotnetRuntimeVersion>6.0.0-preview.7.21377.19</DotnetRuntimeVersion>
<EFCoreVersion>6.0.0-preview.7.21378.4</EFCoreVersion> <!-- [$(DotnetRuntimeVersion), 7.0.0) -->
<DependencyPreviewVersion>$(DotnetRuntimeVersion)</DependencyPreviewVersion>
<AspNetCoreVersion>6.0.0-preview.7.21378.6</AspNetCoreVersion>
<DotnetRuntimeVersion>6.0.0-rc.1.21452.15</DotnetRuntimeVersion>
<EFCoreVersion>6.0.0-rc.1.21452.10</EFCoreVersion> <!-- [$(DotnetRuntimeVersion), 7.0.0) -->
<DependencyPreviewVersion>6.0.0-rc.1.21451.13</DependencyPreviewVersion>
<AspNetCoreVersion>6.0.0-rc.1.21452.15</AspNetCoreVersion>
</PropertyGroup>

<ItemGroup Label="Dependencies">
Expand Down
4 changes: 2 additions & 2 deletions Version.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
- "servicing" - EF Core release independent, code quality production ready, mainly bugfixes
-->
<VersionPrefix>6.0.0</VersionPrefix>
<PreReleaseVersionLabel>preview</PreReleaseVersionLabel>
<PreReleaseVersionIteration>7</PreReleaseVersionIteration>
<PreReleaseVersionLabel>rc</PreReleaseVersionLabel>
<PreReleaseVersionIteration>1</PreReleaseVersionIteration>

<!--
The following properties will automatically be set by CI builds when appropriate:
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": "6.0.0-preview.7.21378.4",
"version": "6.0.0-rc.1.21452.10",
"commands": [
"dotnet-ef"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public static IServiceCollection AddEntityFrameworkMySqlJsonMicrosoft(
Check.NotNull(serviceCollection, nameof(serviceCollection));

new EntityFrameworkRelationalServicesBuilder(serviceCollection)
.TryAdd<IRelationalTypeMappingSourcePlugin, MySqlJsonMicrosoftTypeMappingSourcePlugin>()
.TryAdd<IMethodCallTranslatorPlugin, MySqlJsonMicrosoftMethodCallTranslatorPlugin>()
.TryAdd<IMemberTranslatorPlugin, MySqlJsonMicrosoftMemberTranslatorPlugin>()
.TryAddProviderSpecificServices(
x => x.TryAddSingletonEnumerable<IRelationalTypeMappingSourcePlugin, MySqlJsonMicrosoftTypeMappingSourcePlugin>()
.TryAddSingletonEnumerable<IMethodCallTranslatorPlugin, MySqlJsonMicrosoftMethodCallTranslatorPlugin>()
.TryAddSingletonEnumerable<IMemberTranslatorPlugin, MySqlJsonMicrosoftMemberTranslatorPlugin>()
.TryAddSingleton<IMySqlJsonPocoTranslator, MySqlJsonMicrosoftPocoTranslator>());
x => x.TryAddScopedEnumerable<IMySqlJsonPocoTranslator, MySqlJsonMicrosoftPocoTranslator>());

return serviceCollection;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
// Copyright (c) Pomelo Foundation. All rights reserved.
// Licensed under the MIT. See LICENSE in the project root for license information.

using System;
using System.Reflection;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Scaffolding;

namespace Pomelo.EntityFrameworkCore.MySql.Json.Microsoft.Scaffolding.Internal
{
public class MySqlJsonMicrosoftCodeGeneratorPlugin : ProviderCodeGeneratorPlugin
{
private static readonly MethodInfo _useMicrosoftJsonMethodInfo =
typeof(MySqlJsonMicrosoftDbContextOptionsBuilderExtensions).GetRequiredRuntimeMethod(
nameof(MySqlJsonMicrosoftDbContextOptionsBuilderExtensions.UseMicrosoftJson),
typeof(MySqlDbContextOptionsBuilder),
typeof(MySqlCommonJsonChangeTrackingOptions));

public override MethodCallCodeFragment GenerateProviderOptions()
=> new MethodCallCodeFragment(
nameof(MySqlJsonMicrosoftDbContextOptionsBuilderExtensions.UseMicrosoftJson));
=> new MethodCallCodeFragment(_useMicrosoftJsonMethodInfo);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ public static IServiceCollection AddEntityFrameworkMySqlJsonNewtonsoft(
Check.NotNull(serviceCollection, nameof(serviceCollection));

new EntityFrameworkRelationalServicesBuilder(serviceCollection)
.TryAdd<IRelationalTypeMappingSourcePlugin, MySqlJsonNewtonsoftTypeMappingSourcePlugin>()
.TryAdd<IMethodCallTranslatorPlugin, MySqlJsonNewtonsoftMethodCallTranslatorPlugin>()
.TryAdd<IMemberTranslatorPlugin, MySqlJsonNewtonsoftMemberTranslatorPlugin>()
.TryAddProviderSpecificServices(
x => x
.TryAddSingletonEnumerable<IRelationalTypeMappingSourcePlugin, MySqlJsonNewtonsoftTypeMappingSourcePlugin>()
.TryAddSingletonEnumerable<IMethodCallTranslatorPlugin, MySqlJsonNewtonsoftMethodCallTranslatorPlugin>()
.TryAddSingletonEnumerable<IMemberTranslatorPlugin, MySqlJsonNewtonsoftMemberTranslatorPlugin>()
.TryAddSingleton<IMySqlJsonPocoTranslator, MySqlJsonNewtonsoftPocoTranslator>());
x => x.TryAddScopedEnumerable<IMySqlJsonPocoTranslator, MySqlJsonNewtonsoftPocoTranslator>());

return serviceCollection;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
// Copyright (c) Pomelo Foundation. All rights reserved.
// Licensed under the MIT. See LICENSE in the project root for license information.

using System;
using System.Reflection;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Scaffolding;

namespace Pomelo.EntityFrameworkCore.MySql.Json.Newtonsoft.Scaffolding.Internal
{
public class MySqlJsonNewtonsoftCodeGeneratorPlugin : ProviderCodeGeneratorPlugin
{
private static readonly MethodInfo _useNewtonsoftJsonMethodInfo =
typeof(MySqlJsonNewtonsoftDbContextOptionsBuilderExtensions).GetRequiredRuntimeMethod(
nameof(MySqlJsonNewtonsoftDbContextOptionsBuilderExtensions.UseNewtonsoftJson),
typeof(MySqlDbContextOptionsBuilder),
typeof(MySqlCommonJsonChangeTrackingOptions));

public override MethodCallCodeFragment GenerateProviderOptions()
=> new MethodCallCodeFragment(
nameof(MySqlJsonNewtonsoftDbContextOptionsBuilderExtensions.UseNewtonsoftJson));
=> new MethodCallCodeFragment(_useNewtonsoftJsonMethodInfo);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public static IServiceCollection AddEntityFrameworkMySqlNetTopologySuite(
serviceCollection.TryAddSingleton(NtsGeometryServices.Instance);

new EntityFrameworkRelationalServicesBuilder(serviceCollection)
.TryAdd<IRelationalTypeMappingSourcePlugin, MySqlNetTopologySuiteTypeMappingSourcePlugin>()
.TryAdd<IMethodCallTranslatorPlugin, MySqlNetTopologySuiteMethodCallTranslatorPlugin>()
.TryAdd<IMemberTranslatorPlugin, MySqlNetTopologySuiteMemberTranslatorPlugin>()
.TryAddProviderSpecificServices(
x => x.TryAddSingletonEnumerable<IRelationalTypeMappingSourcePlugin, MySqlNetTopologySuiteTypeMappingSourcePlugin>()
.TryAddSingletonEnumerable<IMethodCallTranslatorPlugin, MySqlNetTopologySuiteMethodCallTranslatorPlugin>()
.TryAddSingletonEnumerable<IMemberTranslatorPlugin, MySqlNetTopologySuiteMemberTranslatorPlugin>()
.TryAddSingletonEnumerable<IMySqlEvaluatableExpressionFilter, MySqlNetTopologySuiteEvaluatableExpressionFilter>());
x => x.TryAddSingletonEnumerable<IMySqlEvaluatableExpressionFilter, MySqlNetTopologySuiteEvaluatableExpressionFilter>());

return serviceCollection;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ public ExtensionInfo(IDbContextOptionsExtension extension)

public override bool IsDatabaseProvider => false;

public override long GetServiceProviderHashCode() => 0;
public override int GetServiceProviderHashCode() => 0;

public override bool ShouldUseSameServiceProvider(DbContextOptionsExtensionInfo other)
=> other is ExtensionInfo;

public override void PopulateDebugInfo(IDictionary<string, string> debugInfo)
=> debugInfo["MySql:" + nameof(MySqlNetTopologySuiteDbContextOptionsBuilderExtensions.UseNetTopologySuite)] = "1";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
// Copyright (c) Pomelo Foundation. All rights reserved.
// Licensed under the MIT. See LICENSE in the project root for license information.

using System;
using System.Reflection;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Scaffolding;

namespace Pomelo.EntityFrameworkCore.MySql.Scaffolding.Internal
{
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public class MySqlNetTopologySuiteCodeGeneratorPlugin : ProviderCodeGeneratorPlugin
{
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
private static readonly MethodInfo _useNetTopologySuiteMethodInfo =
typeof(MySqlNetTopologySuiteDbContextOptionsBuilderExtensions).GetRequiredRuntimeMethod(
nameof(MySqlNetTopologySuiteDbContextOptionsBuilderExtensions.UseNetTopologySuite),
typeof(MySqlDbContextOptionsBuilder));

public override MethodCallCodeFragment GenerateProviderOptions()
=> new MethodCallCodeFragment(
nameof(MySqlNetTopologySuiteDbContextOptionsBuilderExtensions.UseNetTopologySuite));
=> new MethodCallCodeFragment(_useNetTopologySuiteMethodInfo);
}
}
65 changes: 55 additions & 10 deletions src/EFCore.MySql/Design/Internal/MySqlAnnotationCodeGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,64 @@
// Copyright (c) Pomelo Foundation. All rights reserved.
// Licensed under the MIT. See LICENSE in the project root for license information.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Utilities;
using Pomelo.EntityFrameworkCore.MySql.Metadata.Internal;

namespace Pomelo.EntityFrameworkCore.MySql.Design.Internal
{
public class MySqlAnnotationCodeGenerator : AnnotationCodeGenerator
{
private static readonly MethodInfo _modelHasCharSetMethodInfo
= typeof(MySqlModelBuilderExtensions).GetRequiredRuntimeMethod(
nameof(MySqlModelBuilderExtensions.HasCharSet),
typeof(ModelBuilder),
typeof(string),
typeof(DelegationModes?));

private static readonly MethodInfo _modelUseCollationMethodInfo
= typeof(MySqlModelBuilderExtensions).GetRequiredRuntimeMethod(
nameof(MySqlModelBuilderExtensions.UseCollation),
typeof(ModelBuilder),
typeof(string),
typeof(DelegationModes?));

private static readonly MethodInfo _modelUseGuidCollationMethodInfo
= typeof(MySqlModelBuilderExtensions).GetRequiredRuntimeMethod(
nameof(MySqlModelBuilderExtensions.UseGuidCollation),
typeof(ModelBuilder),
typeof(string));

private static readonly MethodInfo _entityTypeHasCharSetMethodInfo
= typeof(MySqlEntityTypeBuilderExtensions).GetRequiredRuntimeMethod(
nameof(MySqlEntityTypeBuilderExtensions.HasCharSet),
typeof(EntityTypeBuilder),
typeof(string),
typeof(DelegationModes?));

private static readonly MethodInfo _entityTypeUseCollationMethodInfo
= typeof(MySqlEntityTypeBuilderExtensions).GetRequiredRuntimeMethod(
nameof(MySqlEntityTypeBuilderExtensions.UseCollation),
typeof(EntityTypeBuilder),
typeof(string),
typeof(DelegationModes?));

private static readonly MethodInfo _propertyHasCharSetMethodInfo
= typeof(MySqlPropertyBuilderExtensions).GetRequiredRuntimeMethod(
nameof(MySqlPropertyBuilderExtensions.HasCharSet),
typeof(PropertyBuilder),
typeof(string));

public MySqlAnnotationCodeGenerator([NotNull] AnnotationCodeGeneratorDependencies dependencies)
: base(dependencies)
{
Expand Down Expand Up @@ -50,7 +93,7 @@ protected override MethodCallCodeFragment GenerateFluentApi(IModel model, IAnnot
{
var delegationModes = model[MySqlAnnotationNames.CharSetDelegation] as DelegationModes?;
return new MethodCallCodeFragment(
nameof(MySqlModelBuilderExtensions.HasCharSet),
_modelHasCharSetMethodInfo,
new[] {annotation.Value}
.AppendIfTrue(delegationModes.HasValue, delegationModes)
.ToArray());
Expand All @@ -60,7 +103,7 @@ protected override MethodCallCodeFragment GenerateFluentApi(IModel model, IAnnot
model[MySqlAnnotationNames.CharSet] is null)
{
return new MethodCallCodeFragment(
nameof(MySqlModelBuilderExtensions.HasCharSet),
_modelHasCharSetMethodInfo,
null,
annotation.Value);
}
Expand All @@ -71,7 +114,7 @@ protected override MethodCallCodeFragment GenerateFluentApi(IModel model, IAnnot
{
var delegationModes = model[MySqlAnnotationNames.CollationDelegation] as DelegationModes?;
return new MethodCallCodeFragment(
nameof(MySqlModelBuilderExtensions.UseCollation),
_modelUseCollationMethodInfo,
new[] {annotation.Value}
.AppendIfTrue(delegationModes.HasValue, delegationModes)
.ToArray());
Expand All @@ -81,15 +124,15 @@ protected override MethodCallCodeFragment GenerateFluentApi(IModel model, IAnnot
model[RelationalAnnotationNames.Collation] is null)
{
return new MethodCallCodeFragment(
nameof(MySqlModelBuilderExtensions.UseCollation),
_modelUseCollationMethodInfo,
null,
annotation.Value);
}

if (annotation.Name == MySqlAnnotationNames.GuidCollation)
{
return new MethodCallCodeFragment(
nameof(MySqlModelBuilderExtensions.UseGuidCollation),
_modelUseGuidCollationMethodInfo,
annotation.Value);
}

Expand All @@ -102,7 +145,7 @@ protected override MethodCallCodeFragment GenerateFluentApi(IEntityType entityTy
{
var delegationModes = entityType[MySqlAnnotationNames.CharSetDelegation] as DelegationModes?;
return new MethodCallCodeFragment(
nameof(MySqlEntityTypeBuilderExtensions.HasCharSet),
_entityTypeHasCharSetMethodInfo,
new[] {annotation.Value}
.AppendIfTrue(delegationModes.HasValue, delegationModes)
.ToArray());
Expand All @@ -112,7 +155,7 @@ protected override MethodCallCodeFragment GenerateFluentApi(IEntityType entityTy
entityType[MySqlAnnotationNames.CharSet] is null)
{
return new MethodCallCodeFragment(
nameof(MySqlEntityTypeBuilderExtensions.HasCharSet),
_entityTypeHasCharSetMethodInfo,
null,
annotation.Value);
}
Expand All @@ -121,7 +164,7 @@ protected override MethodCallCodeFragment GenerateFluentApi(IEntityType entityTy
{
var delegationModes = entityType[MySqlAnnotationNames.CollationDelegation] as DelegationModes?;
return new MethodCallCodeFragment(
nameof(MySqlEntityTypeBuilderExtensions.UseCollation),
_entityTypeUseCollationMethodInfo,
new[] {annotation.Value}
.AppendIfTrue(delegationModes.HasValue, delegationModes)
.ToArray());
Expand All @@ -131,7 +174,7 @@ protected override MethodCallCodeFragment GenerateFluentApi(IEntityType entityTy
entityType[RelationalAnnotationNames.Collation] is null)
{
return new MethodCallCodeFragment(
nameof(MySqlEntityTypeBuilderExtensions.UseCollation),
_entityTypeUseCollationMethodInfo,
null,
annotation.Value);
}
Expand Down Expand Up @@ -198,7 +241,9 @@ protected override MethodCallCodeFragment GenerateFluentApi(IProperty property,
switch (annotation.Name)
{
case MySqlAnnotationNames.CharSet when annotation.Value is string {Length: > 0} charSet:
return new MethodCallCodeFragment(nameof(MySqlPropertyBuilderExtensions.HasCharSet), charSet);
return new MethodCallCodeFragment(
_propertyHasCharSetMethodInfo,
charSet);

default:
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,24 @@ public ExtensionInfo(IDbContextOptionsExtension extension)
=> (MySqlJsonOptionsExtension)base.Extension;

public override bool IsDatabaseProvider => false;
public override long GetServiceProviderHashCode()

public override int GetServiceProviderHashCode()
{
var hashCode = new HashCode();
hashCode.Add(Extension.JsonChangeTrackingOptions);
hashCode.Add(Extension.UseJsonOptionName);
hashCode.Add(Extension.AddEntityFrameworkName);
hashCode.Add(Extension.TypeMappingSourcePluginType);
return hashCode.ToHashCode();
}

public override bool ShouldUseSameServiceProvider(DbContextOptionsExtensionInfo other)
=> other is ExtensionInfo otherInfo &&
Extension.JsonChangeTrackingOptions == otherInfo.Extension.JsonChangeTrackingOptions &&
Extension.UseJsonOptionName == otherInfo.Extension.UseJsonOptionName &&
Extension.AddEntityFrameworkName == otherInfo.Extension.AddEntityFrameworkName &&
Extension.TypeMappingSourcePluginType == otherInfo.Extension.TypeMappingSourcePluginType;

public override void PopulateDebugInfo(IDictionary<string, string> debugInfo)
{
debugInfo["MySql:" + Extension.UseJsonOptionName] = "1";
Expand Down
Loading