SqlSugar/Src/Asp.Net/SqlServerTest/UnitTest/Delete.cs

62 lines
2.0 KiB
C#
Raw Normal View History

2017-05-08 00:33:40 +08:00
using OrmTest.Models;
using OrmTest.UnitTest;
2017-05-08 00:26:36 +08:00
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrmTest
{
2017-05-16 13:55:57 +08:00
public class Delete : UnitTestBase
2017-05-08 00:26:36 +08:00
{
private Delete() { }
public Delete(int eachCount)
{
this.Count = eachCount;
}
public void Init()
{
2017-05-08 00:33:40 +08:00
var db = GetInstance();
//by entity
2017-05-21 13:47:19 +08:00
var t1= db.Deleteable<Student>().Where(new Student() { Id = 1 }).ToSql();
2017-05-26 14:31:19 +08:00
base.Check(@"DELETE FROM [STudent] WHERE [Id] IN ('1') ",
2017-05-21 13:47:19 +08:00
null,
t1.Key,
null, "Delte t1 error"
);
2017-05-08 00:33:40 +08:00
//use lock
2017-05-21 13:47:19 +08:00
var t2 = db.Deleteable<Student>().With(SqlWith.RowLock).ToSql();
2017-05-26 14:31:19 +08:00
base.Check(@"DELETE FROM [STudent] WITH(ROWLOCK) ",
2017-05-21 13:47:19 +08:00
null,
t2.Key,
null, "Delte t2 error"
);
2017-05-08 00:33:40 +08:00
//by primary key
2017-05-21 13:47:19 +08:00
var t3 = db.Deleteable<Student>().In(1).ToSql();
2017-05-26 14:31:19 +08:00
base.Check(@"DELETE FROM [STudent] WHERE [Id] IN ('1') ",
2017-05-21 13:47:19 +08:00
null,
t3.Key,
null, "Delte tt error"
);
2017-05-08 00:33:40 +08:00
//by primary key array
2017-05-21 13:47:19 +08:00
var t4 = db.Deleteable<Student>().In(new int[] { 1,2}).ToSql();
2017-05-26 14:31:19 +08:00
base.Check(@"DELETE FROM [STudent] WHERE [Id] IN ('1','2') ", null, t4.Key, null, "Update t4 error");
2017-05-21 13:47:19 +08:00
2017-05-08 00:33:40 +08:00
//by expression
2017-05-21 13:47:19 +08:00
var t5 = db.Deleteable<Student>().Where(it=>it.Id==1).ToSql();
2017-05-26 14:31:19 +08:00
base.Check(@"DELETE FROM [STudent] WHERE ( [ID] = @Id0 ) ", new List<SugarParameter>() {
2017-05-21 13:48:51 +08:00
new SugarParameter("@Id0",1)
}, t5.Key, t5.Value, "Delte t5 error");
2017-06-22 17:29:53 +08:00
var t6 = db.Deleteable<Student>().Where("id=@id",new { id=1}).ToSql();
base.Check(@"DELETE FROM [STudent] WHERE id=@id", new List<SugarParameter>() {
new SugarParameter("@id",1)
}, t6.Key, t6.Value, "Delte t6 error");
2017-05-08 00:26:36 +08:00
}
}
}