无实体删除

字典删除(支持多库)

//根据字典集合删除 
List<Dictionary<string,object>> list= new List<Dictionary<string,object>>;
list.Add(字典);
db.Deleteable<object>().AS("OrderInfo").WhereColumns(list).ExecuteCommand();

拼SQL删除 (不支持多库)

如果存在一些特殊语法不能做到多库兼容

db.Deleteable<object>().AS("OrderInfo").Where("id=@id",new { id=1}).ExecuteCommand();
db.Deleteable<object>().AS("OrderInfo").Where("id in (@id) ",new {id=new int[]{1,2,3}}).ExecuteCommand();//批量

动态类方式(最完美支持多库)

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  dic=new Dictionary<string, object>(){{ "Id", 1 }, { "Name", "jack" }};        
    var value= db.DynamicBuilder().CreateObjectByType(type,dic);
            
    db.InsertableByObject(value).ExecuteCommand();
    db.UpdateableByObject(value).ExecuteCommand();
    db.DeleteableByObject(value).ExecuteCommand();
    db.StorageableByObject(value).ExecuteCommand();//插入或者更新
    //查询 5.1.4.84-preview09+
    db.QueryableByObject(typeof(OrderSpliteTest)).ToList();


关闭
果糖网