Files
SqlSugar/OrmTest/Demo/Delete.cs

46 lines
1.4 KiB
C#
Raw Normal View History

2017-05-22 01:32:35 +08:00
using OrmTest.Models;
using SqlSugar;
using System;
2017-05-21 22:33:21 +08:00
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrmTest.Demo
{
2017-05-22 00:46:52 +08:00
public class Delete
2017-05-21 22:33:21 +08:00
{
2017-05-22 01:32:35 +08:00
public static void Init()
{
var db = GetInstance();
//by entity
var t1 = db.Deleteable<Student>().Where(new Student() { Id = 1 }).ExecuteCommand();
//use lock
var t2 = db.Deleteable<Student>().With(SqlWith.RowLock).ExecuteCommand();
//by primary key
var t3 = db.Deleteable<Student>().In(1).ExecuteCommand();
//by primary key array
var t4 = db.Deleteable<Student>().In(new int[] { 1, 2 }).ExecuteCommand();
//by expression
var t5 = db.Deleteable<Student>().Where(it => it.Id == 1).ExecuteCommand();
}
public static SqlSugarClient GetInstance()
{
2017-05-23 06:16:59 +08:00
SqlSugarClient db = new SqlSugarClient(new SystemTableConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true });
2017-05-22 01:32:35 +08:00
db.Ado.IsEnableLogEvent = true;
db.Ado.LogEventStarting = (sql, pars) =>
{
Console.WriteLine(sql + "\r\n" + db.RewritableMethods.SerializeObject(pars));
Console.WriteLine();
};
return db;
}
2017-05-21 22:33:21 +08:00
}
}