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.

49 lines
1.9 KiB

8 years ago
using OrmTest.Models;
using SqlSugar;
using System;
8 years ago
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrmTest.Demo
{
8 years ago
public class Delete:DemoBase
8 years ago
{
8 years ago
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();
var t41 = db.Deleteable<Student>().In(new int[] { 1, 2 }.Select(it=>it)).ExecuteCommand();
var t42 = db.Deleteable<Student>().In(new int[] { 1, 2 }.AsEnumerable()).ExecuteCommand();
8 years ago
//by exp key array
var t44 = db.Deleteable<Student>().In(it=>it.SchoolId,new int[] { 1, 2 }).ExecuteCommand();
var t441 = db.Deleteable<Student>().In(it => it.SchoolId,new int[] { 1, 2 }.Select(it => it)).ExecuteCommand();
var t442 = db.Deleteable<Student>().In(it => it.SchoolId,new int[] { 1, 2 }.AsEnumerable()).ExecuteCommand();
var t443 = db.Deleteable<Student>().In(it => it.SchoolId, new int[] { 1, 2 }.ToList()).ExecuteCommand();
8 years ago
//by expression id>1 and id==1
var t5 = db.Deleteable<Student>().Where(it => it.Id > 1).Where(it => it.Id == 1).ExecuteCommand();
7 years ago
var t6 = db.Deleteable<Student>().AS("student").Where(it => it.Id > 1).Where(it => it.Id == 1).ExecuteCommandAsync();
var t7 = db.Deleteable<Student>().Where(p => p.SchoolId == SqlFunc.Subqueryable<School>().Where(s => s.Id == p.SchoolId).Select(s => s.Id)).ExecuteCommand();
7 years ago
t6.Wait();
8 years ago
}
8 years ago
}
}