2019-06-02 15:49:34 +08:00
|
|
|
|
using SqlSugar;
|
|
|
|
|
using System;
|
2019-06-02 15:31:27 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace OrmTest
|
|
|
|
|
{
|
|
|
|
|
public class Demo8_Saveable
|
|
|
|
|
{
|
|
|
|
|
public static void Init()
|
|
|
|
|
{
|
2019-06-02 15:49:34 +08:00
|
|
|
|
Console.WriteLine("");
|
|
|
|
|
Console.WriteLine("#### Saveable Start ####");
|
2019-06-02 15:31:27 +08:00
|
|
|
|
|
2019-06-02 15:49:34 +08:00
|
|
|
|
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
|
|
|
|
|
{
|
|
|
|
|
DbType = DbType.SqlServer,
|
|
|
|
|
ConnectionString = Config.ConnectionString,
|
|
|
|
|
InitKeyType = InitKeyType.Attribute,
|
|
|
|
|
IsAutoCloseConnection = true,
|
|
|
|
|
AopEvents = new AopEvents
|
|
|
|
|
{
|
|
|
|
|
OnLogExecuting = (sql, p) =>
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(sql);
|
|
|
|
|
Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//insert or update
|
2021-08-28 22:30:33 +08:00
|
|
|
|
var x= db.Storageable<Order>(new Order() { Id=1, Name="jack" }).ToStorage();
|
|
|
|
|
x.AsUpdateable.ExecuteCommand();
|
|
|
|
|
x.AsInsertable.ExecuteCommand();
|
2019-06-02 15:49:34 +08:00
|
|
|
|
|
2021-11-23 18:12:05 +08:00
|
|
|
|
|
|
|
|
|
var x2 = db.Storageable<Order>(new Order() { Id = 0, Name = "jack" }).ToStorage();
|
|
|
|
|
x2.BulkCopy();
|
|
|
|
|
x2.BulkUpdate();
|
2019-06-02 15:49:34 +08:00
|
|
|
|
Console.WriteLine("");
|
|
|
|
|
Console.WriteLine("#### Saveable End ####");
|
2019-06-02 15:31:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|