Add Expression Method MappingColumn

This commit is contained in:
sunkaixuan 2017-07-04 00:06:50 +08:00
parent f1a6d80f44
commit 86152ef707
5 changed files with 27 additions and 1 deletions

View File

@ -30,6 +30,7 @@ namespace OrmTest.UnitTest
ExtendDate();
//SqlFun methods
MappingColumn();
IIF();
IIF2();
#region StringIsNullOrEmpty
@ -588,7 +589,17 @@ namespace OrmTest.UnitTest
}, "HasNumber error");
}
private void MappingColumn() {
Expression<Func<Student, bool>> exp = it => SqlFunc.MappingColumn(it.Id,"Name") == 1;
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
base.Check(value, pars, "(Name = @Const1 )", new List<SugarParameter>()
{
new SugarParameter("@Const1",1)
}, "MappingColumn error");
}
private void IIF()
{
Expression<Func<Student, bool>> exp = it => SqlFunc.IIF(it.Id == 1, 1, 2)==1;

View File

@ -247,5 +247,12 @@ namespace SqlSugar
var parameter = model.Args[0];
return string.Format("COUNT({0})", parameter.MemberName);
}
public virtual string MappingColumn(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
var parameter1 = model.Args[1];
return string.Format("{0}", parameter1.MemberValue);
}
}
}

View File

@ -45,5 +45,6 @@ namespace SqlSugar
string AggregateMin(MethodCallExpressionModel model);
string AggregateMax(MethodCallExpressionModel model);
string AggregateCount(MethodCallExpressionModel model);
string MappingColumn(MethodCallExpressionModel model);
}
}

View File

@ -83,5 +83,6 @@ namespace SqlSugar
public static TResult AggregateMin<TResult>(TResult thisValue) { throw new NotSupportedException("This method is not supported by the current parameter"); }
public static TResult AggregateMax<TResult>(TResult thisValue) { throw new NotSupportedException("This method is not supported by the current parameter"); }
public static TResult AggregateCount<TResult>(TResult thisValue) { throw new NotSupportedException("This method is not supported by the current parameter"); }
public static TResult MappingColumn<TResult>(TResult oldColumnName,string newColumnName) { throw new NotSupportedException("This method is not supported by the current parameter"); }
}
}

View File

@ -234,6 +234,12 @@ namespace SqlSugar
return this.Context.DbMehtods.AggregateMax(model);
case "AggregateCount":
return this.Context.DbMehtods.AggregateCount(model);
case "MappingColumn":
var mappingColumnResult = this.Context.DbMehtods.MappingColumn(model);
var isValid= model.Args[0].IsMember&&model.Args[1].IsMember==false;
Check.Exception(!isValid, "SqlFunc.MappingColumn parameters error, The property name on the left, string value on the right");
this.Context.Parameters.RemoveAll(it => it.ParameterName == model.Args[1].MemberName.ObjToString());
return mappingColumnResult;
default:
break;
}