upload efcore 5.0.7

This commit is contained in:
xuejiaming 2021-06-16 16:36:10 +08:00
parent 352e2a07fa
commit b4ee59181d
10 changed files with 75 additions and 14 deletions

View File

@ -8,9 +8,9 @@
Release | EF Core | .NET Standard | .NET (Core) | Sql Server | [Pomelo.EntityFrameworkCore.MySql](https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql)
--- | --- | --- | --- | --- | ---
[5.1.x.x](https://www.nuget.org/packages/ShardingCore/5.1.0.9) | >= 5.0.x | 2.1 | 3.0+ | >= 2012 | 5.0.0-alpha.2
[3.1.x.x](https://www.nuget.org/packages/ShardingCore/3.1.0.9) | 3.1.10 | 2.0 | 2.0+ | >= 2012 | 3.2.4
[2.1.x.x](https://www.nuget.org/packages/ShardingCore/2.1.0.9) | 2.2.6 | 2.0 | 2.0+ | >= 2008 | 2.2.6
[5.1.x.x](https://www.nuget.org/packages/ShardingCore/5.1.0.20) | >= 5.0.x | 2.1 | 3.0+ | >= 2012 | 5.0.0-alpha.2
[3.1.x.x](https://www.nuget.org/packages/ShardingCore/3.1.0.20) | 3.1.10 | 2.0 | 2.0+ | >= 2012 | 3.2.4
[2.1.x.x](https://www.nuget.org/packages/ShardingCore/2.1.0.20) | 2.2.6 | 2.0 | 2.0+ | >= 2008 | 2.2.6
- [开始](#开始)

View File

@ -1,8 +1,8 @@
:start
::定义版本
set EFCORE2=2.1.0.11
set EFCORE3=3.1.0.11
set EFCORE5=5.1.0.11
set EFCORE2=2.1.0.20
set EFCORE3=3.1.0.20
set EFCORE5=5.1.0.20
::删除所有bin与obj下的文件
@echo off

View File

@ -14,7 +14,7 @@ namespace Sample.SqlServer.Domain.Entities
/// <summary>
/// 用户Id用于分表
/// </summary>
[ShardingTableKey]
[ShardingTableKey(TailPrefix = "")]
public string Id { get; set; }
/// <summary>
/// 用户名称

View File

@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Sample.SqlServer.Domain.Entities;
using ShardingCore.Core;
using ShardingCore.Core.VirtualRoutes;
using ShardingCore.Core.VirtualRoutes.TableRoutes;
namespace Sample.SqlServer.Shardings
{
public class TestVRoute : AbstractShardingOperatorVirtualTableRoute<SysUserMod, string>
{
protected override string ConvertToShardingKey(object shardingKey)
{
return shardingKey.ToString();
}
public override string ShardingKeyToTail(object shardingKey)
{
throw new NotImplementedException();
}
//数据库已经存在的tail
public override List<string> GetAllTails()
{
return new List<string>() {"", "1"};
}
protected override Expression<Func<string, bool>> GetRouteToFilter(string shardingKey, ShardingOperatorEnum shardingOperator)
{
var t = ShardingKeyToTail(shardingKey);
switch (shardingOperator)
{
case ShardingOperatorEnum.Equal: return tail => tail == t;
default:
{
#if DEBUG
Console.WriteLine($"shardingOperator is not equal scan all table tail");
#endif
return tail => true;
}
}
}
}
}

View File

@ -12,7 +12,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="5.0.0-alpha.2" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="5.0.0" />
</ItemGroup>
<ItemGroup>

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
@ -14,7 +14,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.7" />
</ItemGroup>
<ItemGroup>

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.Common;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Query.Internal;
@ -31,6 +32,7 @@ namespace ShardingCore.SqlServer
private readonly Dictionary<string, ShareDbContextWrapItem> _contextWrapItems =
new Dictionary<string, ShareDbContextWrapItem>();
public SqlServerDbContextOptionsProvider(ILoggerFactory loggerFactory,IShardingCoreOptions shardingCoreOptions)
{
_loggerFactory = loggerFactory;
@ -40,8 +42,7 @@ namespace ShardingCore.SqlServer
{
if (!_contextWrapItems.ContainsKey(connectKey))
{
var connectionString = _shardingCoreOptions.GetShardingConfig(connectKey).ConnectionString;
var connection = new SqlConnection(connectionString);
var connection = GetSqlConnection(connectKey);
var dbContextOptions = CreateDbContextOptionBuilder(connectKey)
.UseSqlServer(connection)
.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking)
@ -55,6 +56,13 @@ namespace ShardingCore.SqlServer
}
return _contextWrapItems[connectKey].ContextOptions;
}
private SqlConnection GetSqlConnection(string connectKey)
{
var connectionString = _shardingCoreOptions.GetShardingConfig(connectKey).ConnectionString;
return new SqlConnection(connectionString);
}
private DbContextOptionsBuilder CreateDbContextOptionBuilder(string connectKey)
{
var shardingConfigEntry = _shardingCoreOptions.GetShardingConfig(connectKey);

View File

@ -1,4 +1,5 @@
using System;
using System.Data.Common;
using Microsoft.EntityFrameworkCore;
namespace ShardingCore.DbContexts.VirtualDbContexts
@ -17,5 +18,6 @@ namespace ShardingCore.DbContexts.VirtualDbContexts
/// <param name="connectKey"></param>
/// <returns></returns>
DbContextOptions GetDbContextOptions(string connectKey);
}
}

View File

@ -10,6 +10,10 @@ namespace ShardingCore
*/
public class ShardingContainer
{
private ShardingContainer()
{
}
public static IServiceProvider Services { get; private set; }
/// <summary>
/// 静态注入

View File

@ -14,8 +14,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="5.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="5.0.7" />
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="5.0.0" />
</ItemGroup>