-
Notifications
You must be signed in to change notification settings - Fork 1.3k
3.2 Dynamic Insert
果糖网 edited this page Jul 21, 2024
·
5 revisions
// Can be Dictionary or List<Dictionary >
var dc= new Dictionary<string, object>();
dc.Add("name", "1");
dc.Add("CreateTime", DateTime.Now);
db.Insertable(dc).AS("student").ExecuteCommand();
db.InsertableByDynamic(new { name="",price=1 })
.AS("OrderInfo")
.ExecuteCommand();
Select<Object>().ToList() This is the dynamic type
ExpandoObject ex = new ExpandoObject();
var dic= (IDictionary<string, object>)(ex);
dic.Add("name", "1");
dic.Add("id", SnowFlakeSingle.Instance.NextId());
db.Insertable(new Dictionary<string, object>(ex)).AS("StudentWithSnowflake08").ExecuteCommand();
db.Fastest<System.Data.DataTable>().AS("order").BulkCopy(dataTable);
This feature is better for multi-library support and can support features that are only available to entities such as 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()// Cache the KEY combined by the table name and field name
.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(); // Insert or update
// Query 5.1.4.84-preview09+
db.QueryableByObject(typeof(OrderSpliteTest)).ToList();