5.0.1.3 版本发布 返回

求助
8 699

1、支持无限级插入,并修复之前2级插入BUG

2、添加ToTreeList 完成

3、PgSql geometry类型 支持

3、ConditionalType添加EqualsNull 

4、 Select中 bool?=bool 表达式解析Bug  


下个版本发布需求和BUG 请在下面回复


热忱回答8

  • 新功能: 树型查询功能

    var tree = db.Queryable<Tree>().ToTree(it=>it.Child,it=>it.ParentId,0); //第三个参数为0代表 parent为0是第一级
    //实体
    public class Tree
    {
            [SqlSugar.SugarColumn(IsPrimaryKey =true)]
            public int Id { getset; }
            public string Name { getset; }
            public int ParentId { getset; }
            [SqlSugar.SugarColumn(IsIgnore = true)]
            public List<Tree> Child { getset; }
    }


    0 回复
  • 新功能多级插入:

    db.Insertable(new Order()
     {
                    Name = "订单 1",
                    CustomId = 1,
                    Price = 100,
                    CreateTime = DateTime.Now,
                    Id = 0,
                    Items = new List<OrderItem>() {
                          new OrderItem(){
                               CreateTime=DateTime.Now,
                               OrderId=0,
                                Price=1,
                                 ItemId=1
                           },
                          new OrderItem(){
                               CreateTime=DateTime.Now,
                               OrderId=0,
                                Price=2,
                                 ItemId=2
                           }
                     }
                })
    //OrderItem中的OrderId自动取上级的主键            
    .AddSubList(it => it.Items.First().OrderId).ExecuteReturnPrimaryKey();
    //如果有多个子结果这里还能在.AddSubList


    无限级插入

    var list=new List<Country1>()
                {
                   new Country1(){
                         Id=1,
                           Name="中国",
                         Provinces=new List<Province1>(){
                                new Province1{
                                     Id=1001,
                                     Name="江苏",
                                      citys=List1
                                },
                               new Province1{
                                     Id=1002,
                                     Name="上海",
                                      citys=List2
                                },
                               new Province1{
                                     Id=1003,
                                     Name="北京",
                                     citys=List3
                                }
                           }
                     },
                     new Country1(){
                          Name="美国",
                          Id=2,
                          Provinces=new List<Province1>()
                          {
                              new Province1(){
                                   Name="美国小A",
                                   Id=20001
                              },
                             new Province1(){
                                   Name="美国小b",
                                   Id=20002
                              }
                          }
                      },
                     new Country1(){
                          Name="英国",
                          Id=3
                      }
                };
    //开始插入
    db.Insertable(list)
    .AddSubList(it=>new SubInsertTree()
    {
         Expression=it.Provinces.First().CountryId,//CountryId自动填充
         ChildExpression=new List<SubInsertTree>() {
                    new SubInsertTree(){
                      Expression=it.Provinces.First()
                                      .citys.First()
                                      .ProvinceId//ProvinceId自动填充
                    }
          }
    })
    //如果有多个子结果这里还能在.AddSubList
    .ExecuteReturnPrimaryKey();
    
    
    //实体
    
        public class Country1
        {
            [SqlSugar.SugarColumn(IsPrimaryKey = true,IsIdentity =true)]
            public int Id { get; set; }
            public string Name { get; set; }
    
            [SqlSugar.SugarColumn(IsIgnore = true)]
            public List<Province1> Provinces { get; set; }
        }
    
        public class Province1
        {
            [SqlSugar.SugarColumn(IsPrimaryKey = true,IsIdentity =true)]
            public int Id { get; set; }
            public string Name { get; set; }
            public int CountryId { get; set; }
            [SqlSugar.SugarColumn(IsIgnore = true)]
            public List<City1> citys { get; set; }
        }
    
        public class City1
        {
            [SqlSugar.SugarColumn(IsPrimaryKey = true,IsIdentity =true)]
            public int Id { get; set; }
            public int ProvinceId { get; set; }
            public string Name { get; set; }
        }




    0 回复
  • 大佬,能修复下Select 查询对象 Json集合为null的问题吗?项目中等着用,谢谢

    已升级到5.0.1.3,postgresql数据类型为json的时候,连表查询json数据没转换出来,下面是demo

    using SqlSugar;

    using System;

    using System.Collections.Generic;


    namespace PgSqlTest

    {

        internal class Program

        {

            [SugarTable("User")]

            public class User

            {

                [SugarColumn(IsNullable = false, ColumnDataType = "uuid", IsPrimaryKey = true)]

                public Guid Id { get; set; }


                /// <summary>

                /// 部门名称

                /// </summary>

                [SugarColumn(IsNullable = false)]

                public string Name { get; set; }


                /// <summary>

                /// 用户部门

                /// </summary>

                [SugarColumn(IsNullable = false, IsJson = true, ColumnDataType = "json")]

                public List<Department> UserDpt { get; set; }

            }


            [SugarTable("User2")]

            public class User2

            {

                [SugarColumn(IsNullable = false, ColumnDataType = "uuid", IsPrimaryKey = true)]

                public Guid Id { get; set; }


                [SugarColumn(IsNullable = false, ColumnDataType = "uuid")]

                public Guid UserId { get; set; }

            }


            public class Department

            {

                public Guid Id { get; set; }

                public string Name { get; set; }

            }


            private static void Main(string[] args)

            {

                SqlSugarClient db = new SqlSugarClient(

                 new ConnectionConfig()

                 {

                     ConnectionString = "*",

                     DbType = DbType.PostgreSQL,//设置数据库类型

                     IsAutoCloseConnection = true,//自动释放数据务,如果存在事务,在事务结束后释放

                     InitKeyType = InitKeyType.Attribute //从实体特性中读取主键自增列信息

                 });

                db.Aop.OnError = (exp) =>//SQL报错

                {

                    string sql = exp.Sql;

                    //exp.sql 这样可以拿到错误SQL

                };

                //db.DbMaintenance.CreateDatabase();

                db.CodeFirst.InitTables(typeof(User), typeof(User2));

                List<Department> departments = new List<Department>();

                departments.Add(new Department { Id = Guid.NewGuid(), Name = "研发部" });

                departments.Add(new Department { Id = Guid.NewGuid(), Name = "市场部" });

                Guid userId = Guid.NewGuid();

                User user = new User

                {

                    Id = userId,

                    Name = "张三",

                    UserDpt = departments

                };

                db.Insertable(user).ExecuteCommand();

                User2 user2 = new User2();

                user2.Id = Guid.NewGuid();

                user2.UserId = userId;


                db.Insertable(user2).ExecuteCommand();

                var data = db.Queryable<User, User2>((a, b) => new object[] { JoinType.Inner, a.Id == b.UserId })

                    .Where((a, b) => a.Id == userId)

                    .Select((a, b) => new

                    {

                        User = a,//这里面的json集合没数据

                        Items = a.UserDpt

                    }).ToList();

                Console.ReadKey();

            }

        }

    }



    0 回复
  • @Mr、谢:你先这么用 


    .ToList().Select(it=>new { a=it,dep=it.UserDpt}).ToList();

    0 回复
  • @Mr、谢:我本地已修复后面版本会发布

    0 回复
  • @fate stay night:太感谢了

    0 回复
  • 有没有级联修改? 或者同一个方法实现级联新增和修改?


    0 回复
  • 随风 随风 VIP0
    9小时前

    ISugarQueryable的Select方法使用Tuple报错。

    错误写法:

    dbContent.Queryable<AcigaParkingOutvehicleModel>()
                    .GroupBy(it => new { it.projectUuid, it.typeValue })
                    .Select(it => new Tuple<string, int, int>(it.projectUuid, it.typeValue, SqlFunc.AggregateCount(1)))
                    .ToList();

    需要这样写才不会报错:

    dbContent.Queryable<AcigaParkingOutvehicleModel>().AS($"outvehicle_{zoneRID}")
                    .GroupBy(it => new { it.projectUuid, it.typeValue })
                    .Select(it=>new { it.projectUuid, it.typeValue ,count= SqlFunc.AggregateCount(1) })
                    .ToList()
                    .Select(it => new Tuple<string, int, int>(it.projectUuid, it.typeValue, it.count))
                    .ToList();

    请问是不是sqlsugar还不支持元组呢?

    0 回复

版块

学习文档

新注册

发布达人

回贴达人