修复嵌套表达式
This commit is contained in:
parent
8d4066433c
commit
a34db8c165
|
@ -447,6 +447,8 @@ namespace Sample.MySql.Controllers
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<IActionResult> Get16()
|
public async Task<IActionResult> Get16()
|
||||||
{
|
{
|
||||||
|
_defaultTableDbContext.ReadWriteSeparationWriteOnly();
|
||||||
|
|
||||||
var sysUserMod = await _defaultTableDbContext.Set<SysUserMod>().FirstOrDefaultAsync();
|
var sysUserMod = await _defaultTableDbContext.Set<SysUserMod>().FirstOrDefaultAsync();
|
||||||
sysUserMod.Age = new Random().Next(1,999);
|
sysUserMod.Age = new Random().Next(1,999);
|
||||||
await _defaultTableDbContext.SaveChangesAsync();
|
await _defaultTableDbContext.SaveChangesAsync();
|
||||||
|
@ -483,6 +485,18 @@ namespace Sample.MySql.Controllers
|
||||||
// var sysUserMods2 = await _defaultTableDbContext.Set<SysTest>().FromSqlRaw("select * from SysTest where id='2'").ToListAsync();
|
// var sysUserMods2 = await _defaultTableDbContext.Set<SysTest>().FromSqlRaw("select * from SysTest where id='2'").ToListAsync();
|
||||||
return Ok(sysUserMods);
|
return Ok(sysUserMods);
|
||||||
}
|
}
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<IActionResult> Get20()
|
||||||
|
{
|
||||||
|
var dateTime = new DateTime(2022,1,1);
|
||||||
|
var queryable = _defaultTableDbContext.Set<SysUserLogByMonth>().Where(o=>o.Time>dateTime).Select(o=>o.Id);
|
||||||
|
var sysUserMods = await _defaultTableDbContext.SysUserMod.AsNoTracking()
|
||||||
|
.Where(o => queryable.Contains(o.Id)).ToListAsync();
|
||||||
|
|
||||||
|
// var sysUserMods1 = await _defaultTableDbContext.Set<SysUserMod>().FromSqlRaw("select * from SysUserMod where id='2'").ToListAsync();
|
||||||
|
// var sysUserMods2 = await _defaultTableDbContext.Set<SysTest>().FromSqlRaw("select * from SysTest where id='2'").ToListAsync();
|
||||||
|
return Ok(sysUserMods);
|
||||||
|
}
|
||||||
|
|
||||||
// public void batachSave()
|
// public void batachSave()
|
||||||
// {
|
// {
|
||||||
|
|
|
@ -25,7 +25,6 @@ namespace ShardingCore.Sharding.Parsers.Visitors
|
||||||
/// Email: 326308290@qq.com
|
/// Email: 326308290@qq.com
|
||||||
internal class ShardingQueryPrepareVisitor : ExpressionVisitor
|
internal class ShardingQueryPrepareVisitor : ExpressionVisitor
|
||||||
{
|
{
|
||||||
private readonly IShardingDbContext _shardingDbContext;
|
|
||||||
private bool isNotSupport;
|
private bool isNotSupport;
|
||||||
private ShardingQueryableUseConnectionModeOptions shardingQueryableUseConnectionModeOptions;
|
private ShardingQueryableUseConnectionModeOptions shardingQueryableUseConnectionModeOptions;
|
||||||
private ShardingQueryableAsRouteOptions shardingQueryableAsRouteOptions;
|
private ShardingQueryableAsRouteOptions shardingQueryableAsRouteOptions;
|
||||||
|
@ -41,10 +40,13 @@ namespace ShardingCore.Sharding.Parsers.Visitors
|
||||||
|
|
||||||
public ShardingQueryPrepareVisitor(IShardingDbContext shardingDbContext)
|
public ShardingQueryPrepareVisitor(IShardingDbContext shardingDbContext)
|
||||||
{
|
{
|
||||||
_shardingDbContext = shardingDbContext;
|
|
||||||
_trackerManager = ((DbContext)shardingDbContext).GetShardingRuntimeContext()
|
_trackerManager = ((DbContext)shardingDbContext).GetShardingRuntimeContext()
|
||||||
.GetTrackerManager();
|
.GetTrackerManager();
|
||||||
}
|
}
|
||||||
|
public ShardingQueryPrepareVisitor(ITrackerManager trackerManager)
|
||||||
|
{
|
||||||
|
_trackerManager = trackerManager;
|
||||||
|
}
|
||||||
public ShardingPrepareResult GetShardingPrepareResult()
|
public ShardingPrepareResult GetShardingPrepareResult()
|
||||||
{
|
{
|
||||||
return new ShardingPrepareResult(isNotSupport,
|
return new ShardingPrepareResult(isNotSupport,
|
||||||
|
@ -108,7 +110,13 @@ namespace ShardingCore.Sharding.Parsers.Visitors
|
||||||
object value = fieldInfo.GetValue(container);
|
object value = fieldInfo.GetValue(container);
|
||||||
if (value is IQueryable queryable)
|
if (value is IQueryable queryable)
|
||||||
{
|
{
|
||||||
TryAddShardingEntities(queryable.ElementType, queryable);
|
var shardingQueryPrepareVisitor = new ShardingQueryPrepareVisitor(_trackerManager);
|
||||||
|
shardingQueryPrepareVisitor.Visit(queryable.Expression);
|
||||||
|
var shardingPrepareResult = shardingQueryPrepareVisitor.GetShardingPrepareResult();
|
||||||
|
foreach (var keyValuePair in shardingPrepareResult.QueryEntities)
|
||||||
|
{
|
||||||
|
TryAddShardingEntities(keyValuePair.Key, keyValuePair.Value??queryable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//return Expression.Constant(value);
|
//return Expression.Constant(value);
|
||||||
}
|
}
|
||||||
|
@ -194,6 +202,17 @@ namespace ShardingCore.Sharding.Parsers.Visitors
|
||||||
.Last();
|
.Last();
|
||||||
return node.Arguments[0];
|
return node.Arguments[0];
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (var i = 0; i < node.Arguments.Count; i++)
|
||||||
|
{
|
||||||
|
var nodeArgument = node.Arguments[i];
|
||||||
|
if (typeof(IQueryable).IsAssignableFrom(nodeArgument.Type))
|
||||||
|
{
|
||||||
|
Visit(nodeArgument);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Reference in New Issue