mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 18:52:50 +08:00
- 修复 ISelectGrouping ToSql AsProperty 别名无效问题;
This commit is contained in:
parent
80cfa45f51
commit
818d335ec7
@ -487,6 +487,22 @@ namespace base_entity
|
|||||||
BaseEntity.Initialization(fsql, () => _asyncUow.Value);
|
BaseEntity.Initialization(fsql, () => _asyncUow.Value);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
var groupsql01 = fsql.Select<User1>()
|
||||||
|
.GroupBy(a => new
|
||||||
|
{
|
||||||
|
djjg = a.Id,
|
||||||
|
qllx = a.Nickname,
|
||||||
|
hjhs = a.GroupId
|
||||||
|
})
|
||||||
|
.ToSql(g => new
|
||||||
|
{
|
||||||
|
g.Key.djjg,
|
||||||
|
g.Key.qllx,
|
||||||
|
xhjsl = g.Count(g.Key.djjg),
|
||||||
|
hjzhs = g.Sum(g.Key.hjhs),
|
||||||
|
blywsl = g.Count()
|
||||||
|
}, FieldAliasOptions.AsProperty);
|
||||||
|
|
||||||
using (var uow = fsql.CreateUnitOfWork())
|
using (var uow = fsql.CreateUnitOfWork())
|
||||||
{
|
{
|
||||||
uow.Orm.Select<User1>().ForUpdate().ToList();
|
uow.Orm.Select<User1>().ForUpdate().ToList();
|
||||||
|
@ -277,15 +277,23 @@ namespace FreeSql.Internal
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (parent.CsType == null) parent.CsType = exp.Type;
|
if (parent.CsType == null) parent.CsType = exp.Type;
|
||||||
var pdbfield = parent.DbField = ExpressionLambdaToSql(exp, getTSC());
|
try
|
||||||
if (parent.MapType == null || _tables?.Any(a => a.Table?.IsRereadSql == true) == true)
|
|
||||||
{
|
{
|
||||||
var findcol = SearchColumnByField(_tables, null, parent.DbField);
|
var pdbfield = parent.DbField = ExpressionLambdaToSql(exp, getTSC());
|
||||||
if (parent.MapType == null) parent.MapType = findcol?.Attribute.MapType ?? exp.Type;
|
if (parent.MapType == null || _tables?.Any(a => a.Table?.IsRereadSql == true) == true)
|
||||||
if (findcol != null) pdbfield = _common.RereadColumn(findcol, pdbfield);
|
{
|
||||||
|
var findcol = SearchColumnByField(_tables, null, parent.DbField);
|
||||||
|
if (parent.MapType == null) parent.MapType = findcol?.Attribute.MapType ?? exp.Type;
|
||||||
|
if (findcol != null) pdbfield = _common.RereadColumn(findcol, pdbfield);
|
||||||
|
}
|
||||||
|
field.Append(", ").Append(pdbfield);
|
||||||
|
LocalSetFieldAlias(ref index, _tables != null ||
|
||||||
|
SelectGroupingProvider._ParseExpOnlyDbField.Value != pdbfield);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
SelectGroupingProvider._ParseExpOnlyDbField.Value = null;
|
||||||
}
|
}
|
||||||
field.Append(", ").Append(pdbfield);
|
|
||||||
LocalSetFieldAlias(ref index, true);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -31,6 +31,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
_tables = tables;
|
_tables = tables;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ThreadLocal<string> _ParseExpOnlyDbField = new ThreadLocal<string>();
|
||||||
public override string ParseExp(Expression[] members)
|
public override string ParseExp(Expression[] members)
|
||||||
{
|
{
|
||||||
ParseExpMapResult = null;
|
ParseExpMapResult = null;
|
||||||
@ -52,7 +53,11 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
}
|
}
|
||||||
ParseExpMapResult = read;
|
ParseExpMapResult = read;
|
||||||
if (!_addFieldAlias) return read.DbField;
|
if (!_addFieldAlias) return read.DbField;
|
||||||
if (_comonExp.EndsWithDbNestedField(read.DbField, read.DbNestedField) == false) return $"{read.DbField}{_comonExp._common.FieldAsAlias(read.DbNestedField)}";
|
if (_comonExp.EndsWithDbNestedField(read.DbField, read.DbNestedField) == false)
|
||||||
|
{
|
||||||
|
_ParseExpOnlyDbField.Value = read.DbField;
|
||||||
|
return $"{read.DbField}{_comonExp._common.FieldAsAlias(read.DbNestedField)}";
|
||||||
|
}
|
||||||
return read.DbField;
|
return read.DbField;
|
||||||
case "Value":
|
case "Value":
|
||||||
var curtables = _tables;
|
var curtables = _tables;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user