//字典 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
where条件太灵活可能会有不同数据库不兼容情况
db.Updateable<object>() .AS("Order") .SetColumns("name", 1) .Where("id=1").ExecuteCommand();
根据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();
2016 © donet5.comApache Licence 2.0