Skip to content
果糖网 edited this page Jul 21, 2024 · 5 revisions

1、dictionary insert (support multi-library)

// 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();

2、anonymous object insert (support multi-library)

db.InsertableByDynamic(new   { name="",price=1 })
.AS("OrderInfo")
.ExecuteCommand();

3、Dynamic object insert

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();

4、 BulkCopy

db.Fastest<System.Data.DataTable>().AS("order").BulkCopy(dataTable); 

5、 dynamic class insert perfect support for multi-library +AOP

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();