diff --git a/Examples/base_entity/Program.cs b/Examples/base_entity/Program.cs index 7906b3553..bcf353019 100644 --- a/Examples/base_entity/Program.cs +++ b/Examples/base_entity/Program.cs @@ -555,7 +555,7 @@ static void Main(string[] args) var fsql = new FreeSql.FreeSqlBuilder() .UseAutoSyncStructure(true) .UseNoneCommandParameter(true) - .UseNameConvert(NameConvertType.ToLower) + //.UseNameConvert(NameConvertType.ToLower) //.UseMappingPriority(MappingPriorityType.Attribute, MappingPriorityType.FluentApi, MappingPriorityType.Aop) .UseAdoConnectionPool(true) @@ -596,7 +596,7 @@ static void Main(string[] args) //.UseConnectionString(DataType.QuestDb, "host=localhost;port=8812;username=admin;password=quest;database=qdb;ServerCompatibilityMode=NoTypeLoading;") //.UseConnectionString(DataType.ClickHouse, "DataCompress=False;BufferSize=32768;SocketTimeout=10000;CheckCompressedHash=False;Encrypt=False;Compressor=lz4;Host=192.168.0.121;Port=8125;Database=PersonnelLocation;Username=root;Password=123") - .UseConnectionFactory(DataType.ClickHouse, () => null) + //.UseConnectionFactory(DataType.ClickHouse, () => null) .UseMonitorCommand(cmd => { Console.WriteLine(cmd.CommandText + "\r\n"); @@ -608,16 +608,55 @@ static void Main(string[] args) .UseGenerateCommandParameterWithLambda(true) .Build(); BaseEntity.Initialization(fsql, () => _asyncUow.Value); - #endregion - - var clickhouseSql1 = fsql.Select().Where(a => new[] { 1, 2, 3 }.Contains(a.GroupId)).ToSql(); - var clickhouseVal1 = new[] { 1, 2, 3 }; - var clickhouseSql2 = fsql.Select().Where(a => clickhouseVal1.Contains(a.GroupId)).ToSql(); - var clickhouseSql3 = fsql.Select().Where(a => a.Tags.Contains("tag1")).ToSql(); - var clickhouseVal2 = "tag2"; - var clickhouseSql4 = fsql.Select().Where(a => a.Tags.Contains(clickhouseVal2)).ToSql(); + #endregion + + + var list111222 = fsql.Select() + .InnerJoin((l, p) => l.ProductId == p.ID) + .GroupBy((l, p) => new { p.ID, ShopType = l.ShopType ?? 0 }) + .WithTempQuery(a => new + { + a.Key.ID, + Money = a.Sum(a.Value.Item1.Amount) * a.Key.ShopType + }) + .ToList(); + Console.WriteLine(list111222); + + var list0x1sql = fsql.Select() + .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); + var sql1c2 = fsql.Select() + .GroupBy(a => new { a.Nickname, a.Avatar }) + .WithTempQuery(b => new + { + sum = b.Sum(b.Value.Sort), + b.Key.Nickname, + b.Key.Avatar, + }) + .OrderByDescending(arg => arg.sum) + .ToSql(arg => new + { + str1 = string.Concat(arg.Nickname, '-', arg.Avatar, '-'), + str2 = string.Concat(arg.Nickname, '-', arg.Avatar) + }); //报错 多括号 + //.ToOne(arg => string.Concat(arg.Nickname, '-', arg.Avatar)); //正常 + Console.WriteLine(sql1c2); + + //var clickhouseSql1 = fsql.Select().Where(a => new[] { 1, 2, 3 }.Contains(a.GroupId)).ToSql(); + // var clickhouseVal1 = new[] { 1, 2, 3 }; + // var clickhouseSql2 = fsql.Select().Where(a => clickhouseVal1.Contains(a.GroupId)).ToSql(); + // var clickhouseSql3 = fsql.Select().Where(a => a.Tags.Contains("tag1")).ToSql(); + // var clickhouseVal2 = "tag2"; + // var clickhouseSql4 = fsql.Select().Where(a => a.Tags.Contains(clickhouseVal2)).ToSql(); - fsql.Update() + fsql.Update() .Where(t => t.GroupId == 1) .ExecuteUpdated(); @@ -831,16 +870,6 @@ static void Main(string[] args) fsql.UseJsonMap(); fsql.Select().Where(a => a.FormLocking == null).Count(); - var list0x1sql = fsql.Select() -.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().Where("1=1").ExecuteAffrows(); FreeSql.Internal.Utils.TypeHandlers.TryAdd(typeof(TestIdAndIdentity), new String_TestIdAndIdentity()); @@ -1211,22 +1240,8 @@ static void Main(string[] args) .Set((a, b) => a.Nickname == "b.groupname") .ExecuteAffrows(); - var sql1c2 = fsql.Select() - .GroupBy(a => new { a.Nickname, a.Avatar }) - .WithTempQuery(b => new - { - sum = b.Sum(b.Value.Sort), - b.Key.Nickname, - b.Key.Avatar, - }) - .OrderByDescending(arg => arg.sum) - .ToSql(arg => new - { - str1 = string.Concat(arg.Nickname, '-', arg.Avatar, '-'), - str2 = string.Concat(arg.Nickname, '-', arg.Avatar) - }); //报错 多括号 - //.ToOne(arg => string.Concat(arg.Nickname, '-', arg.Avatar)); //正常 - Console.WriteLine(sql1c2); + + var xp = new Xpb() { @@ -3065,4 +3080,26 @@ public class Test2 public string ItemName { get; set; } public bool IsEnabled { get; set; } -} \ No newline at end of file +} +[JsonObject(MemberSerialization.OptIn), Table(Name = "T_OrderLine111222")] +public partial class OrderLine +{ + + 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_Product111222")] +public partial class Product +{ + public string ID { get; set; } + public string Name { get; set; } + public string Model { get; set; } +} + diff --git a/FreeSql.DbContext/FreeSql.DbContext.xml b/FreeSql.DbContext/FreeSql.DbContext.xml index 341e3d36a..c1335e5e9 100644 --- a/FreeSql.DbContext/FreeSql.DbContext.xml +++ b/FreeSql.DbContext/FreeSql.DbContext.xml @@ -739,15 +739,6 @@ - - - 根据Assembly扫描所有继承IEntityTypeConfiguration<T>的配置类 - - - - - - 创建普通数据上下文档对象 @@ -806,14 +797,5 @@ - - - 批量注入 Repository,可以参考代码自行调整 - - - - - - diff --git a/FreeSql/FreeSql.xml b/FreeSql/FreeSql.xml index 8f213e5ce..8adf6d85f 100644 --- a/FreeSql/FreeSql.xml +++ b/FreeSql/FreeSql.xml @@ -1104,82 +1104,6 @@ - - - 动态创建实体类型 - - - - - 配置Class - - 类名 - 类标记的特性[Table(Name = "xxx")] [Index(xxxx)] - - - - - 配置属性 - - 属性名称 - 属性类型 - 属性标记的特性-支持多个 - - - - - 配置属性 - - 属性名称 - 属性类型 - 该属性是否重写父类属性 - 属性标记的特性-支持多个 - - - - - 配置属性 - - 属性名称 - 属性类型 - 该属性是否重写父类属性 - 属性默认值 - 属性标记的特性-支持多个 - - - - - 配置父类 - - 父类类型 - - - - - Override属性 - - - - - - Emit动态创建出Class - Type - - - - - - 首字母小写 - - - - - - - 首字母大写 - - - - 获取实体的主键值,以 "*|_,[,_|*" 分割,当任意一个主键属性无值时,返回 null @@ -5897,28 +5821,6 @@ 请使用 fsql.InsertDict(dict) 方法插入字典数据 - - - 动态构建Class Type - - - - - - 根据字典,创建 table 对应的实体对象 - - - - - - - - 根据实体对象,创建 table 对应的字典 - - - - - C#: that >= between && that <= and diff --git a/FreeSql/Internal/CommonProvider/SelectProvider/SelectGroupingProvider.cs b/FreeSql/Internal/CommonProvider/SelectProvider/SelectGroupingProvider.cs index fa7a28b08..1917cbfed 100644 --- a/FreeSql/Internal/CommonProvider/SelectProvider/SelectGroupingProvider.cs +++ b/FreeSql/Internal/CommonProvider/SelectProvider/SelectGroupingProvider.cs @@ -20,6 +20,7 @@ public class SelectGroupingProvider : BaseDiyMemberExpression public List _tables; public int _groupByLimit, _groupBySkip; public bool _addFieldAlias; + public bool _flagNestedFieldAlias; public SelectGroupingProvider(IFreeSql orm, Select0Provider select, ReadAnonymousTypeInfo map, string field, CommonExpression comonExp, List tables) { @@ -53,6 +54,7 @@ public override string ParseExp(Expression[] members) } ParseExpMapResult = read; if (!_addFieldAlias) return read.DbField; + if (_flagNestedFieldAlias) return read.DbField; if (_comonExp.EndsWithDbNestedField(read.DbField, read.DbNestedField) == false) { _ParseExpOnlyDbField.Value = read.DbField; @@ -252,7 +254,8 @@ public ISelect WithTempQuery(Expression new { p.ID, ShopType=l.ShopType??0 }).WithTempQuery(a => new { Money = a.Sum(a.Value.Item1.Amount)* a.Key.ShopType }) + var old_field = _field; var fieldsb = new StringBuilder(); if (_map.Childs.Any() == false) fieldsb.Append(", ").Append(_map.DbField).Append(_comonExp.EndsWithDbNestedField(_map.DbField, _map.DbNestedField) ? "" : _comonExp._common.FieldAsAlias(_map.DbNestedField)); foreach (var child in _map.GetAllChilds()) @@ -268,7 +271,8 @@ public ISelect WithTempQuery(Expression