mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-06-28 13:34:32 +08:00
Add Expression Method MappingColumn
This commit is contained in:
parent
f1a6d80f44
commit
86152ef707
@ -30,6 +30,7 @@ namespace OrmTest.UnitTest
|
|||||||
ExtendDate();
|
ExtendDate();
|
||||||
|
|
||||||
//SqlFun methods
|
//SqlFun methods
|
||||||
|
MappingColumn();
|
||||||
IIF();
|
IIF();
|
||||||
IIF2();
|
IIF2();
|
||||||
#region StringIsNullOrEmpty
|
#region StringIsNullOrEmpty
|
||||||
@ -588,7 +589,17 @@ namespace OrmTest.UnitTest
|
|||||||
|
|
||||||
}, "HasNumber error");
|
}, "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()
|
private void IIF()
|
||||||
{
|
{
|
||||||
Expression<Func<Student, bool>> exp = it => SqlFunc.IIF(it.Id == 1, 1, 2)==1;
|
Expression<Func<Student, bool>> exp = it => SqlFunc.IIF(it.Id == 1, 1, 2)==1;
|
||||||
|
@ -247,5 +247,12 @@ namespace SqlSugar
|
|||||||
var parameter = model.Args[0];
|
var parameter = model.Args[0];
|
||||||
return string.Format("COUNT({0})", parameter.MemberName);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,5 +45,6 @@ namespace SqlSugar
|
|||||||
string AggregateMin(MethodCallExpressionModel model);
|
string AggregateMin(MethodCallExpressionModel model);
|
||||||
string AggregateMax(MethodCallExpressionModel model);
|
string AggregateMax(MethodCallExpressionModel model);
|
||||||
string AggregateCount(MethodCallExpressionModel model);
|
string AggregateCount(MethodCallExpressionModel model);
|
||||||
|
string MappingColumn(MethodCallExpressionModel model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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 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 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 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"); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -234,6 +234,12 @@ namespace SqlSugar
|
|||||||
return this.Context.DbMehtods.AggregateMax(model);
|
return this.Context.DbMehtods.AggregateMax(model);
|
||||||
case "AggregateCount":
|
case "AggregateCount":
|
||||||
return this.Context.DbMehtods.AggregateCount(model);
|
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:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user