SqlSugar/Src/Asp.Net/AccessTest/Demo/Demo8_Saveable.cs

50 lines
1.6 KiB
C#
Raw Normal View History

2022-02-20 14:13:19 +08:00
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrmTest
{
public class Demo8_Saveable
{
public static void Init()
{
Console.WriteLine("");
Console.WriteLine("#### Saveable Start ####");
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
{
2022-02-20 14:17:54 +08:00
DbType = DbType.Access,
2022-02-20 14:13:19 +08:00
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
2022-03-24 21:54:53 +08:00
var x= db.Storageable<Order>(new Order() { Id=159, Name="jack" }).ToStorage();
var updateRow=x.AsUpdateable.ExecuteCommand();
2022-02-20 14:13:19 +08:00
x.AsInsertable.ExecuteCommand();
var x2 = db.Storageable<Order>(new Order() { Id = 0, Name = "jack" }).ToStorage();
2022-03-24 21:54:53 +08:00
var updateRow2 = x2.AsUpdateable.ExecuteCommand();
x2.AsInsertable.ExecuteCommand();
2022-02-20 14:13:19 +08:00
2022-03-24 21:54:53 +08:00
db.Saveable(new Order() { Id = 159, Name = "jack" }).ExecuteCommand();
2022-02-20 14:13:19 +08:00
Console.WriteLine("");
Console.WriteLine("#### Saveable End ####");
}
}
}