暴露ShardingDbContextExecutor优化仅take的时候添加skip(0),发布x.3.2.2
This commit is contained in:
parent
fbe7207b86
commit
c1e19efca5
|
@ -1,9 +1,9 @@
|
||||||
:start
|
:start
|
||||||
::定义版本
|
::定义版本
|
||||||
set EFCORE2=2.3.2.01
|
set EFCORE2=2.3.2.02
|
||||||
set EFCORE3=3.3.2.01
|
set EFCORE3=3.3.2.02
|
||||||
set EFCORE5=5.3.2.01
|
set EFCORE5=5.3.2.02
|
||||||
set EFCORE6=6.3.2.01
|
set EFCORE6=6.3.2.02
|
||||||
|
|
||||||
::删除所有bin与obj下的文件
|
::删除所有bin与obj下的文件
|
||||||
@echo off
|
@echo off
|
||||||
|
|
|
@ -10,6 +10,7 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Sample.SqlServerShardingTable.Entities;
|
||||||
using Sample.SqlServerShardingTable.VirtualRoutes;
|
using Sample.SqlServerShardingTable.VirtualRoutes;
|
||||||
using ShardingCore;
|
using ShardingCore;
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ namespace ShardingCore.Sharding
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class AbstractShardingDbContext : DbContext, IShardingDbContext, ISupportShardingTransaction, ISupportShardingReadWrite
|
public abstract class AbstractShardingDbContext : DbContext, IShardingDbContext, ISupportShardingTransaction, ISupportShardingReadWrite
|
||||||
{
|
{
|
||||||
private readonly IShardingDbContextExecutor _shardingDbContextExecutor;
|
protected IShardingDbContextExecutor ShardingDbContextExecutor { get; }
|
||||||
|
|
||||||
|
|
||||||
public AbstractShardingDbContext(DbContextOptions options) : base(options)
|
public AbstractShardingDbContext(DbContextOptions options) : base(options)
|
||||||
|
@ -36,7 +36,7 @@ namespace ShardingCore.Sharding
|
||||||
var wrapOptionsExtension = options.FindExtension<ShardingWrapOptionsExtension>();
|
var wrapOptionsExtension = options.FindExtension<ShardingWrapOptionsExtension>();
|
||||||
if (wrapOptionsExtension != null)
|
if (wrapOptionsExtension != null)
|
||||||
{
|
{
|
||||||
_shardingDbContextExecutor =
|
ShardingDbContextExecutor =
|
||||||
(IShardingDbContextExecutor)Activator.CreateInstance(
|
(IShardingDbContextExecutor)Activator.CreateInstance(
|
||||||
typeof(ShardingDbContextExecutor<>).GetGenericType0(this.GetType()),this);
|
typeof(ShardingDbContextExecutor<>).GetGenericType0(this.GetType()),this);
|
||||||
}
|
}
|
||||||
|
@ -48,16 +48,16 @@ namespace ShardingCore.Sharding
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int ReadWriteSeparationPriority
|
public int ReadWriteSeparationPriority
|
||||||
{
|
{
|
||||||
get => _shardingDbContextExecutor.ReadWriteSeparationPriority;
|
get => ShardingDbContextExecutor.ReadWriteSeparationPriority;
|
||||||
set => _shardingDbContextExecutor.ReadWriteSeparationPriority = value;
|
set => ShardingDbContextExecutor.ReadWriteSeparationPriority = value;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 是否使用读写分离
|
/// 是否使用读写分离
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool ReadWriteSeparation
|
public bool ReadWriteSeparation
|
||||||
{
|
{
|
||||||
get => _shardingDbContextExecutor.ReadWriteSeparation;
|
get => ShardingDbContextExecutor.ReadWriteSeparation;
|
||||||
set => _shardingDbContextExecutor.ReadWriteSeparation = value;
|
set => ShardingDbContextExecutor.ReadWriteSeparation = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -69,7 +69,7 @@ namespace ShardingCore.Sharding
|
||||||
|
|
||||||
public DbContext GetDbContext(string dataSourceName, bool parallelQuery, IRouteTail routeTail)
|
public DbContext GetDbContext(string dataSourceName, bool parallelQuery, IRouteTail routeTail)
|
||||||
{
|
{
|
||||||
return _shardingDbContextExecutor.CreateDbContext(parallelQuery, dataSourceName, routeTail);
|
return ShardingDbContextExecutor.CreateDbContext(parallelQuery, dataSourceName, routeTail);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -80,7 +80,7 @@ namespace ShardingCore.Sharding
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public DbContext CreateGenericDbContext<TEntity>(TEntity entity) where TEntity : class
|
public DbContext CreateGenericDbContext<TEntity>(TEntity entity) where TEntity : class
|
||||||
{
|
{
|
||||||
return _shardingDbContextExecutor.CreateGenericDbContext(entity);
|
return ShardingDbContextExecutor.CreateGenericDbContext(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -392,17 +392,17 @@ namespace ShardingCore.Sharding
|
||||||
//ApplyShardingConcepts();
|
//ApplyShardingConcepts();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
//如果是内部开的事务就内部自己消化
|
//如果是内部开的事务就内部自己消化
|
||||||
if (Database.CurrentTransaction==null&&_shardingDbContextExecutor.IsMultiDbContext)
|
if (Database.CurrentTransaction==null&&ShardingDbContextExecutor.IsMultiDbContext)
|
||||||
{
|
{
|
||||||
using (var tran = Database.BeginTransaction())
|
using (var tran = Database.BeginTransaction())
|
||||||
{
|
{
|
||||||
i = _shardingDbContextExecutor.SaveChanges(acceptAllChangesOnSuccess);
|
i = ShardingDbContextExecutor.SaveChanges(acceptAllChangesOnSuccess);
|
||||||
tran.Commit();
|
tran.Commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
i = _shardingDbContextExecutor.SaveChanges(acceptAllChangesOnSuccess);
|
i = ShardingDbContextExecutor.SaveChanges(acceptAllChangesOnSuccess);
|
||||||
}
|
}
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
|
@ -423,11 +423,11 @@ namespace ShardingCore.Sharding
|
||||||
//ApplyShardingConcepts();
|
//ApplyShardingConcepts();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
//如果是内部开的事务就内部自己消化
|
//如果是内部开的事务就内部自己消化
|
||||||
if (Database.CurrentTransaction==null && _shardingDbContextExecutor.IsMultiDbContext)
|
if (Database.CurrentTransaction==null && ShardingDbContextExecutor.IsMultiDbContext)
|
||||||
{
|
{
|
||||||
using (var tran = await Database.BeginTransactionAsync(cancellationToken))
|
using (var tran = await Database.BeginTransactionAsync(cancellationToken))
|
||||||
{
|
{
|
||||||
i = await _shardingDbContextExecutor.SaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken);
|
i = await ShardingDbContextExecutor.SaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken);
|
||||||
#if EFCORE2
|
#if EFCORE2
|
||||||
tran.Commit();
|
tran.Commit();
|
||||||
#endif
|
#endif
|
||||||
|
@ -438,7 +438,7 @@ namespace ShardingCore.Sharding
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
i = await _shardingDbContextExecutor.SaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken);
|
i = await ShardingDbContextExecutor.SaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -454,7 +454,7 @@ namespace ShardingCore.Sharding
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_shardingDbContextExecutor.Dispose();
|
ShardingDbContextExecutor.Dispose();
|
||||||
base.Dispose();
|
base.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -468,35 +468,35 @@ namespace ShardingCore.Sharding
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await _shardingDbContextExecutor.DisposeAsync();
|
await ShardingDbContextExecutor.DisposeAsync();
|
||||||
|
|
||||||
await base.DisposeAsync();
|
await base.DisposeAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public Task RollbackAsync(CancellationToken cancellationToken = new CancellationToken())
|
public Task RollbackAsync(CancellationToken cancellationToken = new CancellationToken())
|
||||||
{
|
{
|
||||||
return _shardingDbContextExecutor.RollbackAsync(cancellationToken);
|
return ShardingDbContextExecutor.RollbackAsync(cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task CommitAsync(CancellationToken cancellationToken = new CancellationToken())
|
public Task CommitAsync(CancellationToken cancellationToken = new CancellationToken())
|
||||||
{
|
{
|
||||||
return _shardingDbContextExecutor.CommitAsync(cancellationToken);
|
return ShardingDbContextExecutor.CommitAsync(cancellationToken);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public void NotifyShardingTransaction()
|
public void NotifyShardingTransaction()
|
||||||
{
|
{
|
||||||
_shardingDbContextExecutor.NotifyShardingTransaction();
|
ShardingDbContextExecutor.NotifyShardingTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Rollback()
|
public void Rollback()
|
||||||
{
|
{
|
||||||
_shardingDbContextExecutor.Rollback();
|
ShardingDbContextExecutor.Rollback();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Commit()
|
public void Commit()
|
||||||
{
|
{
|
||||||
_shardingDbContextExecutor.Commit();
|
ShardingDbContextExecutor.Commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,10 @@
|
||||||
using Microsoft.EntityFrameworkCore.Storage;
|
using Microsoft.EntityFrameworkCore.Storage;
|
||||||
using ShardingCore.Core.VirtualRoutes.TableRoutes.RouteTails.Abstractions;
|
using ShardingCore.Core.VirtualRoutes.TableRoutes.RouteTails.Abstractions;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using ShardingCore.Sharding.ShardingDbContextExecutors;
|
||||||
|
|
||||||
namespace ShardingCore.Sharding.Abstractions
|
namespace ShardingCore.Sharding.Abstractions
|
||||||
{
|
{
|
||||||
|
@ -71,6 +73,8 @@ namespace ShardingCore.Sharding.Abstractions
|
||||||
/// commit
|
/// commit
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void Commit();
|
void Commit();
|
||||||
|
|
||||||
|
IDictionary<string, IDataSourceDbContext> GetCurrentDbContexts();
|
||||||
#if !EFCORE2
|
#if !EFCORE2
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// rollback async
|
/// rollback async
|
||||||
|
|
|
@ -45,7 +45,7 @@ namespace ShardingCore.Core.Internal.StreamMerge.ReWrite
|
||||||
}
|
}
|
||||||
|
|
||||||
if (take.HasValue)
|
if (take.HasValue)
|
||||||
reWriteQueryable = reWriteQueryable.Take(take.Value + skip.GetValueOrDefault());
|
reWriteQueryable = reWriteQueryable.Skip(0).Take(take.Value + skip.GetValueOrDefault());
|
||||||
//包含group by
|
//包含group by
|
||||||
if (extraEntry.GroupByContext.GroupExpression != null)
|
if (extraEntry.GroupByContext.GroupExpression != null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -270,6 +270,11 @@ namespace ShardingCore.Sharding.ShardingDbContextExecutors
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IDictionary<string, DbContext> GetCurrentContexts()
|
||||||
|
{
|
||||||
|
return _dataSourceDbContexts;
|
||||||
|
}
|
||||||
|
|
||||||
public void Rollback()
|
public void Rollback()
|
||||||
{
|
{
|
||||||
if (IsDefault)
|
if (IsDefault)
|
||||||
|
|
|
@ -38,7 +38,7 @@ namespace ShardingCore.Sharding.ShardingDbContextExecutors
|
||||||
|
|
||||||
Task<int> SaveChangesAsync(bool acceptAllChangesOnSuccess,CancellationToken cancellationToken = new CancellationToken());
|
Task<int> SaveChangesAsync(bool acceptAllChangesOnSuccess,CancellationToken cancellationToken = new CancellationToken());
|
||||||
|
|
||||||
|
IDictionary<string, DbContext> GetCurrentContexts();
|
||||||
|
|
||||||
void Rollback();
|
void Rollback();
|
||||||
void Commit(int dataSourceCount);
|
void Commit(int dataSourceCount);
|
||||||
|
|
|
@ -180,6 +180,11 @@ namespace ShardingCore.Sharding.ShardingDbContextExecutors
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IDictionary<string, IDataSourceDbContext> GetCurrentDbContexts()
|
||||||
|
{
|
||||||
|
return _dbContextCaches;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue