SqlSugar 4.9.8更新内容 返回

求助
2 695

1.简化了Mapper一对多多对多功能,以前功能也兼容,性能也是非常好没有任何外键配置


 var list= db.Queryable<MyOrder>()
                .Mapper(it => it.masterPerson, it => it.masterPersonId)
                .Mapper(it => it.Persons, it => it.orgId)
                .Mapper(it => it.OrderItems, it => it.OrderItems.First().masterOrderId)
                .Mapper(it => it.OrderItemSignle, it => it.OrderItemSignle.masterOrderId)
                .Mapper(it => {
                    it.orderName = it.orderName + "aa";//
                })
                .ToList();
  public class MyOrder
        {
            [SqlSugar.SugarColumn(IsPrimaryKey=true,IsIdentity =true)]
            public int orderId { get; set; }
            public string orderName { get; set; }
            public string orgId { get; set; }
            public int masterPersonId { get; set; }
            [SqlSugar.SugarColumn(IsIgnore = true)]
            public List<OrderItem> OrderItems { get; set; }
            [SqlSugar.SugarColumn(IsIgnore = true)]
            public OrderItem OrderItemSignle { get; set; }
            [SqlSugar.SugarColumn(IsIgnore = true)]
            public List<Person> Persons { get; set; }
            [SqlSugar.SugarColumn(IsIgnore = true)]
            public Person masterPerson { get; set; }
        }
        public class Person
        {
            [SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
            public int PersonId { get; set; }
            public string orgId { get; set; }
        }
        public class OrderItem
        {
            [SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
            public int itemId { get; set; }
            public int masterOrderId { get; set; }
        }


2.添加了新API db.Saveable 来智能对数据进行更新或者插入,支持集合操作

  //获取刚插入的实体
  var entity= db.Insertable<Student>(new Student() { Name = "abc" }).ExecuteReturnEntity();
  
  
             db.Saveable<Student>(entity).ExecuteReturnEntity();
            //UPDATE [STudent]  SET
            //[SchoolId]=@SchoolId,[Name]=@Name,[CreateTime]=@CreateTime WHERE[Id] = @Id
            
            
            db.Saveable<Student>(new Student() { Name="" }).ExecuteReturnEntity();
            // INSERT INTO[STudent]
            //([SchoolId],[Name],[CreateTime])
            // VALUES
            //(@SchoolId, @Name, @CreateTime); SELECT SCOPE_IDENTITY();


3添加了 Queryable.WhereClass功能 可以对集体类非NULL数据生成查询

var db = GetInstance();
            var list=db.Queryable<Student>().WhereClass(new WhereClass() {  Id=1 }).ToList();
            //where id=1
            var list2 = db.Queryable<Student>().WhereClass(new WhereClass() {  Name="a"},ignoreDefaultValue:true).ToList();
            //where name="a"
            var list3 = db.Queryable<Student>().WhereClass(new WhereClass() { Name = "a" }).ToList();
            //where id=0 and name="a"
            var list4 = db.Queryable<Student>().WhereClass(new WhereClass() { SchoolId="1", Name = "a" },ignoreDefaultValue:true).ToList();
            //school=1,name=a
            var list5= db.Queryable<Student>().WhereClass(new WhereClass() { SchoolId = "1", Name = "a" }).ToList();
            //school=1,name=a,id=0
            var list6 = db.Queryable<Student>().WhereClass(new List<WhereClass>() {
                                             new WhereClass(){ Name="a",SchoolId="1" },
                                             new WhereClass(){ Id=1 }
            },ignoreDefaultValue:true).ToList();
            //(name=a and schoolid=1) or id=1
            var list7 = db.Queryable<Student>().WhereClass(new List<WhereClass>() {
                                             new WhereClass(){ Name="a",SchoolId="1" },
                                             new WhereClass(){ Id=1 }
            }).ToList();
            //(name=a and schoolid=1 and id=0) or id=1


4.完善了Sqlite CodeFirst功能

5.近期轻微BUG,上个版本非常稳定可以不考虑升级

热忱回答2

  • 边界 边界 VIP0
    1个月前

    Saveable每次调用都会先执行查询,更新也是全部字段更新。不是更新修改过都属性

    0 回复
  • @边界:更新有指定列功能,还有过滤列功能

    0 回复

版块

学习文档

最新会员

发布达人

回贴达人