Add Deleteable.In overload

This commit is contained in:
610262374@qq.com 2018-11-24 16:55:46 +08:00
parent 194c7249a0
commit f21bde7664
3 changed files with 47 additions and 3 deletions

View File

@ -28,6 +28,13 @@ namespace OrmTest.Demo
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 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();
//by expression id>1 and id==1
var t5 = db.Deleteable<Student>().Where(it => it.Id > 1).Where(it => it.Id == 1).ExecuteCommand();

View File

@ -20,6 +20,7 @@ namespace SqlSugar
public bool IsAs { get; set; }
public bool IsEnableDiffLogEvent { get; set; }
public DiffLogModel diffModel { get; set; }
public List<string> tempPrimaryKeys { get; set; }
public EntityInfo EntityInfo
{
get
@ -265,6 +266,34 @@ namespace SqlSugar
return this;
}
public IDeleteable<T> In<PkType>(Expression<Func<T, object>> inField, PkType primaryKeyValue)
{
var lamResult = DeleteBuilder.GetExpressionValue(inField, ResolveExpressType.FieldSingle);
var fieldName = lamResult.GetResultString();
tempPrimaryKeys = new List<string>() { fieldName };
var result = In(primaryKeyValue);;
tempPrimaryKeys = null;
return this;
}
public IDeleteable<T> In<PkType>(Expression<Func<T, object>> inField, PkType[] primaryKeyValues)
{
var lamResult = DeleteBuilder.GetExpressionValue(inField, ResolveExpressType.FieldSingle);
var fieldName = lamResult.GetResultString();
tempPrimaryKeys = new List<string>() { fieldName };
var result = In(primaryKeyValues);
tempPrimaryKeys = null;
return this;
}
public IDeleteable<T> In<PkType>(Expression<Func<T, object>> inField, List<PkType> primaryKeyValues)
{
var lamResult = DeleteBuilder.GetExpressionValue(inField, ResolveExpressType.FieldSingle);
var fieldName = lamResult.GetResultString();
tempPrimaryKeys = new List<string>() { fieldName };
var result = In(primaryKeyValues);
tempPrimaryKeys = null;
return this;
}
public IDeleteable<T> With(string lockString)
{
if (this.Context.CurrentConnectionConfig.DbType == DbType.SqlServer)
@ -283,7 +312,11 @@ namespace SqlSugar
private List<string> GetPrimaryKeys()
{
if (this.Context.IsSystemTablesConfig)
if (tempPrimaryKeys.HasValue())
{
return tempPrimaryKeys;
}
else if (this.Context.IsSystemTablesConfig)
{
return this.Context.DbMaintenance.GetPrimaries(this.Context.EntityMaintenance.GetTableName(this.EntityInfo.EntityName));
}
@ -315,7 +348,8 @@ namespace SqlSugar
private void TaskStart<Type>(Task<Type> result)
{
if (this.Context.CurrentConnectionConfig.IsShardSameThread) {
if (this.Context.CurrentConnectionConfig.IsShardSameThread)
{
Check.Exception(true, "IsShardSameThread=true can't be used async method");
}
result.Start();

View File

@ -22,6 +22,9 @@ namespace SqlSugar
IDeleteable<T> In<PkType>(PkType primaryKeyValue);
IDeleteable<T> In<PkType>(PkType[] primaryKeyValues);
IDeleteable<T> In<PkType>(List<PkType> primaryKeyValues);
IDeleteable<T> In<PkType>(Expression<Func<T,object>> inField,PkType primaryKeyValue);
IDeleteable<T> In<PkType>(Expression<Func<T, object>> inField,PkType[] primaryKeyValues);
IDeleteable<T> In<PkType>(Expression<Func<T, object>> inField,List<PkType> primaryKeyValues);
IDeleteable<T> Where(string whereString,object parameters=null);
IDeleteable<T> Where(string whereString, SugarParameter parameter);
IDeleteable<T> Where(string whereString, SugarParameter[] parameters);