Skip to content

Commit

Permalink
- 修复 GroupBy + WithTempQuery + .Key.xx + 特性名与实体不同 + 三元表达式解析问题;
Browse files Browse the repository at this point in the history
  • Loading branch information
2881099 committed Sep 9, 2023
1 parent 29943a0 commit f117b14
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 6 deletions.
37 changes: 31 additions & 6 deletions Examples/base_entity/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -600,12 +600,16 @@ static void Main(string[] args)
BaseEntity.Initialization(fsql, () => _asyncUow.Value);
#endregion

fsql.GlobalFilter.Apply<User1>("test01", a => a.IsDeleted == false);

var updatejoin031sql = fsql.Update<User1>()
.Join<UserGroup>((a, b) => a.GroupId == b.Id)
.Set((a, b) => b.GroupName == a.Username + "b.groupname")
.ToSql();
var list0x1sql = fsql.Select<OrderLine22x, Product22x>()
.InnerJoin((l, p) => l.ProductId == p.ID)
.GroupBy((l, p) => new { p.ID, l.ShopType })
.WithTempQuery(a => new {
a.Key.ID,
Money2 = a.Key.ShopType,
Money = a.Key.ShopType == 1 ? a.Value.Item1.Price * a.Value.Item1.Amount : a.Value.Item1.Price * a.Value.Item1.Amount * 1.1m
})
.ToSql();
Console.WriteLine(list0x1sql);

fsql.Delete<TypeHandler01>().Where("1=1").ExecuteAffrows();
FreeSql.Internal.Utils.TypeHandlers.TryAdd(typeof(TestIdAndIdentity), new String_TestIdAndIdentity());
Expand Down Expand Up @@ -2631,3 +2635,24 @@ public override TestIdAndIdentity Deserialize(object value)
}
}
}
public partial class OrderLine22x
{

public string Id { get; set; }
public string OrderId { get; set; }

public string ShopId { get; set; }
[JsonProperty, Column(Name = "Shop_Type")]
public int? ShopType { get; set; }
public string ProductId { get; set; }
public decimal Price { get; set; }
public decimal Amount { get; set; }
}
[JsonObject(MemberSerialization.OptIn), Table(Name = "T_Product22x", DisableSyncStructure = true)]

public partial class Product22x
{
public string ID { get; set; }
public string Name { get; set; }
public string Model { get; set; }
}
9 changes: 9 additions & 0 deletions FreeSql.DbContext/FreeSql.DbContext.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions FreeSql/Internal/CommonExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,19 @@ void LocalSetFieldAlias(ref int localIndex, bool isdiymemexp)
field.Append(_common.FieldAsAlias(parent.DbNestedField));
}
}
var isGroupAddField = true;
var isGroupAddFieldProvider = diymemexp as SelectGroupingProvider;
if (isGroupAddFieldProvider?._addFieldAlias == true)
{
switch (exp.NodeType)
{
case ExpressionType.Conditional:
case ExpressionType.Call:
isGroupAddField = false;
isGroupAddFieldProvider._addFieldAlias = false;
break;
}
}

Func<ExpTSC> getTSC = () => new ExpTSC { _tables = _tables, _tableRule = _tableRule, diymemexp = diymemexp, tbtype = SelectTableInfoType.From, isQuoteName = true, isDisableDiyParse = false, style = ExpressionStyle.Where, whereGlobalFilter = whereGlobalFilter, dbParams = select?._params }; //#462 添加 DbParams 解决
switch (exp.NodeType)
Expand Down Expand Up @@ -542,6 +555,7 @@ void LocalSetFieldAlias(ref int localIndex, bool isdiymemexp)
field.Append(", ").Append(parent.DbField);
LocalSetFieldAlias(ref index, false);
if (parent.CsType == null && exp.Type.IsValueType) parent.CsType = exp.Type;
if (isGroupAddField == false && isGroupAddFieldProvider != null) isGroupAddFieldProvider._addFieldAlias = true;
return false;
}
public object ReadAnonymous(ReadAnonymousTypeInfo parent, DbDataReader dr, ref int index, bool notRead, ReadAnonymousDbValueRef dbValue, int rowIndex,
Expand Down

0 comments on commit f117b14

Please sign in to comment.