无实体更新

字典更新 (支持多库)

//字典
var dt = new Dictionary<string, object>();
            dt.Add("id", 1);
            dt.Add("name", "jack");
            dt.Add("createTime", DateTime.Now);
var t66 = db.Updateable(dt).AS("student").WhereColumns("id").ExecuteCommand();
 
//字典集合
var dtList = new List<Dictionary<string, object>>();
dtList.Add(dt);
dtList.Add(dt2);
var t666 = db.Updateable(dtList).AS("student").WhereColumns("id").ExecuteCommand();


匿名对象更新(支持多库)

 db.InsertableByDynamic
        (new { id = 1, name = "a" })
        .AS("order")
        .WhereColumns("id").ExecuteCommand();
        
   //sql 
   UPDATE [order]  SET
            [name]=@name  WHERE [id]=@id
   @id:1,@name:a


SQL方式更新

where条件太灵活可能会有不同数据库不兼容情况

 db.Updateable<object>()
                .AS("Order")
                .SetColumns("name", 1)
                .Where("id=1").ExecuteCommand();


BulkCopy更新 (需要较新版本)

根据ID为条件更新 

db.Fastest<DataTable>().AS("Order").BulkUpdate(datatable, new string[] { "id" });


动态建类更新

上面的可能简单些,不过该功能主要用于产品对多库兼容更好,可以支持AOP等功能

var type = db.DynamicBuilder().CreateClass("table1", new SugarTable()
    {
    })
    .CreateProperty("Id", typeof(int),new SugarColumn() { IsPrimaryKey = true, IsIdentity = true })
    .CreateProperty("Name",typeof(string), new SugarColumn() { })
    .WithCache()//缓存起来根据表名和字段名组合的KEY    、
    .BuilderType();

    db.CodeFirst.InitTables(type);            
    var  value= db.DynamicBuilder().CreateObjectByType(type,new Dictionary<string, object>() { { "Id", 1 }, { "Name", "jack" } });
           
    db.InsertableByObject(value).ExecuteCommand();
    db.UpdateableByObject(value).ExecuteCommand();
    db.DeleteableByObject(value).ExecuteCommand();
    db.StorageableByObject(value).ExecuteCommand();//插入或者更新
    db.Queryable<object>().AsType(type).Filter(type).ToList();


文档:SqlSugar5.0