SqlSugar源码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.6 KiB

8 years ago
using OrmTest.Models;
using OrmTest.UnitTest;
8 years ago
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrmTest
{
8 years ago
public class Delete : UnitTestBase
8 years ago
{
private Delete() { }
public Delete(int eachCount)
{
this.Count = eachCount;
}
public void Init()
{
8 years ago
var db = GetInstance();
//by entity
8 years ago
var t1= db.Deleteable<Student>().Where(new Student() { Id = 1 }).ToSql();
8 years ago
base.Check(@"DELETE FROM [STudent] WHERE [Id] IN ('1') ",
8 years ago
null,
t1.Key,
null, "Delte t1 error"
);
8 years ago
//use lock
8 years ago
var t2 = db.Deleteable<Student>().With(SqlWith.RowLock).ToSql();
8 years ago
base.Check(@"DELETE FROM [STudent] WITH(ROWLOCK) ",
8 years ago
null,
t2.Key,
null, "Delte t2 error"
);
8 years ago
//by primary key
8 years ago
var t3 = db.Deleteable<Student>().In(1).ToSql();
8 years ago
base.Check(@"DELETE FROM [STudent] WHERE [Id] IN ('1') ",
8 years ago
null,
t3.Key,
null, "Delte tt error"
);
8 years ago
//by primary key array
8 years ago
var t4 = db.Deleteable<Student>().In(new int[] { 1,2}).ToSql();
8 years ago
base.Check(@"DELETE FROM [STudent] WHERE [Id] IN ('1','2') ", null, t4.Key, null, "Update t4 error");
8 years ago
8 years ago
//by expression
8 years ago
var t5 = db.Deleteable<Student>().Where(it=>it.Id==1).ToSql();
8 years ago
base.Check(@"DELETE FROM [STudent] WHERE ( [ID] = @Id0 ) ", new List<SugarParameter>() {
8 years ago
new SugarParameter("@Id0",1)
}, t5.Key, t5.Value, "Delte t5 error");
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");
var t7 = base.GetInstanceByAttribute().Deleteable<DeleteTestTable>().Where(new List<DeleteTestTable>() {
new DeleteTestTable() { Id=1, Id2="x" },
new DeleteTestTable() { Id=2, Id2="x1" }
}).ToSql();
base.Check("DELETE FROM [DeleteTestTable] WHERE (([Id]=N'1'AND [Id2]=N'x')OR ([Id]=N'2'AND [Id2]=N'x1')) ",null, t7.Key, null,
"Delte t7 error");
8 years ago
}
}
public class DeleteTestTable {
[SugarColumn(IsPrimaryKey =true)]
public int Id { get; set; }
[SugarColumn(IsPrimaryKey = true)]
public string Id2 { get; set; }
}
8 years ago
}