Delete In Support Enumable

This commit is contained in:
sunkaixuan 2018-10-16 08:20:45 +08:00
parent 7b398f5050
commit 0abccebf83
3 changed files with 15 additions and 1 deletions

View File

@ -25,6 +25,8 @@ namespace OrmTest.Demo
//by primary key array //by primary key array
var t4 = db.Deleteable<Student>().In(new int[] { 1, 2 }).ExecuteCommand(); 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();
//by expression id>1 and id==1 //by expression id>1 and id==1
var t5 = db.Deleteable<Student>().Where(it => it.Id > 1).Where(it => it.Id == 1).ExecuteCommand(); var t5 = db.Deleteable<Student>().Where(it => it.Id > 1).Where(it => it.Id == 1).ExecuteCommand();

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
@ -231,6 +232,17 @@ namespace SqlSugar
public IDeleteable<T> In<PkType>(PkType primaryKeyValue) public IDeleteable<T> In<PkType>(PkType primaryKeyValue)
{ {
if (typeof(PkType).FullName.IsCollectionsList())
{
var newValues = new List<object>();
foreach (var item in primaryKeyValue as IEnumerable)
{
newValues.Add(item);
}
return In(newValues);
}
In(new PkType[] { primaryKeyValue }); In(new PkType[] { primaryKeyValue });
return this; return this;
} }

View File

@ -151,7 +151,7 @@ namespace SqlSugar
} }
public static bool IsCollectionsList(this string thisValue) public static bool IsCollectionsList(this string thisValue)
{ {
return (thisValue + "").StartsWith("System.Collections.Generic.List"); return (thisValue + "").StartsWith("System.Collections.Generic.List")|| (thisValue + "").StartsWith("System.Collections.Generic.IEnumerable");
} }
public static bool IsStringArray(this string thisValue) public static bool IsStringArray(this string thisValue)
{ {