Browse Source

Support both `MySql.EntityFrameworkCore` & `Pomelo.EntityFrameworkCore.MySql`.

pull/23392/head
maliming 9 months ago
parent
commit
3ff71c052e
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 1
      Directory.Packages.props
  2. 1
      framework/src/Volo.Abp.EntityFrameworkCore.MySQL/Volo.Abp.EntityFrameworkCore.MySQL.csproj
  3. 34
      framework/src/Volo.Abp.EntityFrameworkCore.MySQL/Volo/Abp/EntityFrameworkCore/AbpDbContextConfigurationContextMySQLExtensions.cs
  4. 45
      framework/src/Volo.Abp.EntityFrameworkCore.MySQL/Volo/Abp/EntityFrameworkCore/AbpDbContextOptionsMySQLExtensions.cs
  5. 2
      framework/src/Volo.Abp.EntityFrameworkCore.MySQL/Volo/Abp/EntityFrameworkCore/ConnectionStrings/MySqlConnectionStringChecker.cs

1
Directory.Packages.props

@ -137,6 +137,7 @@
<PackageVersion Include="Polly" Version="8.5.2" />
<PackageVersion Include="Polly.Extensions.Http" Version="3.0.0" />
<PackageVersion Include="Pomelo.EntityFrameworkCore.MySql" Version="9.0.0-preview.3.efcore.9.0.0" />
<PackageVersion Include="MySql.EntityFrameworkCore" Version="9.0.6" />
<PackageVersion Include="Quartz" Version="3.14.0" />
<PackageVersion Include="Quartz.Extensions.DependencyInjection" Version="3.14.0" />
<PackageVersion Include="Quartz.Plugins.TimeZoneConverter" Version="3.14.0" />

1
framework/src/Volo.Abp.EntityFrameworkCore.MySQL/Volo.Abp.EntityFrameworkCore.MySQL.csproj

@ -22,6 +22,7 @@
<ItemGroup>
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" />
<PackageReference Include="MySql.EntityFrameworkCore" />
</ItemGroup>
</Project>

34
framework/src/Volo.Abp.EntityFrameworkCore.MySQL/Volo/Abp/EntityFrameworkCore/AbpDbContextConfigurationContextMySQLExtensions.cs

@ -1,16 +1,29 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore;
using System;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Volo.Abp.EntityFrameworkCore.DependencyInjection;
namespace Volo.Abp.EntityFrameworkCore;
public static class AbpDbContextConfigurationContextMySQLExtensions
{
/// <summary>
/// This extension method is configuring the use Pomelo.EntityFrameworkCore.MySql as the database provider.
/// </summary>
[Obsolete("Use UsePomeloMySQL instead.")]
public static DbContextOptionsBuilder UseMySQL(
[NotNull] this AbpDbContextConfigurationContext context,
Action<MySqlDbContextOptionsBuilder>? mySQLOptionsAction = null)
Action<Microsoft.EntityFrameworkCore.Infrastructure.MySqlDbContextOptionsBuilder>? mySQLOptionsAction = null)
{
return context.UsePomeloMySQL(mySQLOptionsAction);
}
/// <summary>
/// This extension method is configuring the use Pomelo.EntityFrameworkCore.MySql as the database provider.
/// </summary>
public static DbContextOptionsBuilder UsePomeloMySQL(
[NotNull] this AbpDbContextConfigurationContext context,
Action<Microsoft.EntityFrameworkCore.Infrastructure.MySqlDbContextOptionsBuilder>? mySQLOptionsAction = null)
{
if (context.ExistingConnection != null)
{
@ -31,4 +44,21 @@ public static class AbpDbContextConfigurationContextMySQLExtensions
});
}
}
/// <summary>
/// This extension method is configuring the use MySql.EntityFrameworkCore as the database provider.
/// </summary>
public static DbContextOptionsBuilder UseMySQL(
[NotNull] this AbpDbContextConfigurationContext context,
Action<MySql.EntityFrameworkCore.Infrastructure.MySQLDbContextOptionsBuilder>? mySQLOptionsAction = null)
{
if (context.ExistingConnection != null)
{
return context.DbContextOptions.UseMySQL(context.ExistingConnection, mySQLOptionsAction);
}
else
{
return context.DbContextOptions.UseMySQL(context.ConnectionString, mySQLOptionsAction);
}
}
}

45
framework/src/Volo.Abp.EntityFrameworkCore.MySQL/Volo/Abp/EntityFrameworkCore/AbpDbContextOptionsMySQLExtensions.cs

@ -1,14 +1,51 @@
using JetBrains.Annotations;
using System;
using Microsoft.EntityFrameworkCore.Infrastructure;
namespace Volo.Abp.EntityFrameworkCore;
public static class AbpDbContextOptionsMySQLExtensions
{
[Obsolete("Use UsePomeloMySQL instead.")]
public static void UseMySQL(
[NotNull] this AbpDbContextOptions options,
Action<MySqlDbContextOptionsBuilder>? mySQLOptionsAction = null)
[NotNull] this AbpDbContextOptions options,
Action<Microsoft.EntityFrameworkCore.Infrastructure.MySqlDbContextOptionsBuilder>? mySQLOptionsAction = null)
{
options.UsePomeloMySQL(mySQLOptionsAction);
}
[Obsolete("Use UsePomeloMySQL instead.")]
public static void UseMySQL<TDbContext>(
[NotNull] this AbpDbContextOptions options,
Action<Microsoft.EntityFrameworkCore.Infrastructure.MySqlDbContextOptionsBuilder>? mySQLOptionsAction = null)
where TDbContext : AbpDbContext<TDbContext>
{
options.UsePomeloMySQL<TDbContext>(mySQLOptionsAction);
}
public static void UsePomeloMySQL(
[NotNull] this AbpDbContextOptions options,
Action<Microsoft.EntityFrameworkCore.Infrastructure.MySqlDbContextOptionsBuilder>? mySQLOptionsAction = null)
{
options.Configure(context =>
{
context.UsePomeloMySQL(mySQLOptionsAction);
});
}
public static void UsePomeloMySQL<TDbContext>(
[NotNull] this AbpDbContextOptions options,
Action<Microsoft.EntityFrameworkCore.Infrastructure.MySqlDbContextOptionsBuilder>? mySQLOptionsAction = null)
where TDbContext : AbpDbContext<TDbContext>
{
options.Configure<TDbContext>(context =>
{
context.UsePomeloMySQL(mySQLOptionsAction);
});
}
public static void UseMySQL(
[NotNull] this AbpDbContextOptions options,
Action<MySql.EntityFrameworkCore.Infrastructure.MySQLDbContextOptionsBuilder>? mySQLOptionsAction = null)
{
options.Configure(context =>
{
@ -18,7 +55,7 @@ public static class AbpDbContextOptionsMySQLExtensions
public static void UseMySQL<TDbContext>(
[NotNull] this AbpDbContextOptions options,
Action<MySqlDbContextOptionsBuilder>? mySQLOptionsAction = null)
Action<MySql.EntityFrameworkCore.Infrastructure.MySQLDbContextOptionsBuilder>? mySQLOptionsAction = null)
where TDbContext : AbpDbContext<TDbContext>
{
options.Configure<TDbContext>(context =>

2
framework/src/Volo.Abp.EntityFrameworkCore.MySQL/Volo/Abp/EntityFrameworkCore/ConnectionStrings/MySqlConnectionStringChecker.cs

@ -1,6 +1,6 @@
using System;
using System.Threading.Tasks;
using MySqlConnector;
using MySql.Data.MySqlClient;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;

Loading…
Cancel
Save