增加savechange对AutoTransactionsEnabled的支持[#133]

This commit is contained in:
xuejiaming 2022-04-02 16:06:18 +08:00
parent 138ef9c137
commit 0a655416f5
4 changed files with 19 additions and 3 deletions

View File

@ -148,8 +148,19 @@ namespace Sample.SqlServer.Controllers
//await _defaultTableDbContext.SaveChangesAsync();
var sresultx1121222 = await _defaultTableDbContext.Set<SysUserMod>().Where(o => o.Id == "198").MaxAsync(o => o.Age);
var unionUserIds = await _defaultTableDbContext.Set<SysUserMod>().Select(o => new UnionUserId() { UserId = o.Id })
.Union(_defaultTableDbContext.Set<SysUserSalary>().Select(o => new UnionUserId() { UserId = o.UserId })).UseUnionAllMerge().ToListAsync();
var unionUserIdCounts = await _defaultTableDbContext.Set<SysUserMod>().Select(o => new UnionUserId() { UserId = o.Id })
.Union(_defaultTableDbContext.Set<SysUserSalary>().Select(o => new UnionUserId() { UserId = o.UserId })).UseUnionAllMerge().CountAsync();
var hashSet = unionUserIds.Select(o => o.UserId).ToHashSet();

View File

@ -6,7 +6,9 @@ using Microsoft.EntityFrameworkCore;
using Sample.SqlServerShardingAll.Entities;
using ShardingCore;
using ShardingCore.Core.VirtualDatabase.VirtualDataSources;
using ShardingCore.Core.VirtualDatabase.VirtualTables;
using ShardingCore.DynamicDataSources;
using ShardingCore.Helpers;
namespace Sample.SqlServerShardingAll.Controllers
{
@ -22,6 +24,9 @@ namespace Sample.SqlServerShardingAll.Controllers
}
public async Task<IActionResult> Query()
{
var virtualTableManager = ShardingContainer.GetService<IVirtualTableManager<MyDbContext>>();
virtualTableManager.AddVirtualTable()
#region
var virtualDataSource = ShardingContainer.GetRequiredCurrentVirtualDataSource<MyDbContext>();

View File

@ -28,7 +28,7 @@ namespace ShardingCore.DbContexts
{
shardingTableDbContext.RouteTail = routeTail;
}
var dbContextModel = dbContext.Model;
_ = dbContext.Model;
return dbContext;
}

View File

@ -398,7 +398,7 @@ namespace ShardingCore.Sharding
//ApplyShardingConcepts();
int i = 0;
//如果是内部开的事务就内部自己消化
if (Database.CurrentTransaction==null&&ShardingDbContextExecutor.IsMultiDbContext)
if (Database.AutoTransactionsEnabled&&Database.CurrentTransaction==null&&ShardingDbContextExecutor.IsMultiDbContext)
{
using (var tran = Database.BeginTransaction())
{
@ -429,7 +429,7 @@ namespace ShardingCore.Sharding
//ApplyShardingConcepts();
int i = 0;
//如果是内部开的事务就内部自己消化
if (Database.CurrentTransaction==null && ShardingDbContextExecutor.IsMultiDbContext)
if (Database.AutoTransactionsEnabled && Database.CurrentTransaction==null && ShardingDbContextExecutor.IsMultiDbContext)
{
using (var tran = await Database.BeginTransactionAsync(cancellationToken))
{