-
Notifications
You must be signed in to change notification settings - Fork 1.3k
3.1 Insert
果糖网 edited this page Jul 2, 2024
·
1 revision
//insert entity or List<entity>
db.Insertable(insertObj).ExecuteCommand();
//Insert Dictionary or List<Dictionary >
var dt = new Dictionary<string, object>();
dt.Add("name", "1");
dt.Add("CreateTime", null);
db.Insertable(dt).AS("student").ExecuteReturnIdentity();
Final Execution Method | description |
---|---|
ExecuteCommand | Return the number of inserted rows |
ExecuteReturnIdentity | Return identity int |
ExecuteReturnBigIdentity | Return identity long |
ExecuteReturnEntity | Return entity |
ExecuteCommandIdentityIntoEntity | Return the number of inserted rows and update entity identity property |
//Ignore Name testId
db.Insertable(insertObj).IgnoreColumns(it => new { it.Name, it.TestId }).ExecuteReturnIdentity();
db.Insertable(insertObj).IgnoreColumns( "Name","TestId").ExecuteReturnIdentity();
//Only insert Name and SchoolId
db.Insertable(insertObj).InsertColumns(it => new { it.Name, it.SchoolId }).ExecuteReturnIdentity();
db.Insertable(insertObj).InsertColumns("Name","SchoolId").ExecuteReturnIdentity();
//ignore null columns
db.Insertable(insertObj2).IgnoreColumnsNull().ExecuteCommand();
//Use Lock
db.Insertable(insertObj).With(SqlWith.UpdLock).ExecuteCommand();
For example, MYSQL special symbol
[SugarColumn(IsTranscoding =true)]
public string Url { get; set; }
[SqlSugar.SugarColumn(IsOnlyIgnoreInsert = true)]
public DateTime CreateTime { get; set; }
Db.Insertable(new Order() { Name = "a", CustomId = 1 }).ExecuteCommandAsync();