Dynamic join

This commit is contained in:
sunkaixuan
2023-10-07 03:54:24 +08:00
parent ce8b47907e
commit fe53352168
3 changed files with 15 additions and 2 deletions

View File

@@ -64,6 +64,12 @@ namespace SqlSugar
} }
return this; return this;
} }
public QueryMethodInfo AddJoinInfo(Type joinEntityType,Dictionary<string,Type> keyIsShortName_ValueIsType_Dictionary, FormattableString expOnWhere, JoinType type = JoinType.Left)
{
var method = QueryableObj.GetType().GetMyMethod("AddJoinInfo", 4,typeof(Type), typeof(Dictionary<string, Type>), typeof(FormattableString), typeof(JoinType));
this.QueryableObj = method.Invoke(QueryableObj, new object[] { joinEntityType, keyIsShortName_ValueIsType_Dictionary, expOnWhere, type });
return this;
}
public QueryMethodInfo AddJoinInfo(Type joinEntityType, string shortName, string onWhere, JoinType type = JoinType.Left) public QueryMethodInfo AddJoinInfo(Type joinEntityType, string shortName, string onWhere, JoinType type = JoinType.Left)
{ {
var method = QueryableObj.GetType().GetMyMethod("AddJoinInfo", 4, typeof(string), typeof(string), typeof(string), typeof(JoinType)); var method = QueryableObj.GetType().GetMyMethod("AddJoinInfo", 4, typeof(string), typeof(string), typeof(string), typeof(JoinType));

View File

@@ -580,6 +580,13 @@ namespace SqlSugar
QueryBuilder.Parameters.Add(parameter); QueryBuilder.Parameters.Add(parameter);
return this; return this;
} }
public ISugarQueryable<T> AddJoinInfo(Type JoinType, Dictionary<string, Type> keyIsShortName_ValueIsType_Dictionary, FormattableString onExpString, JoinType type = JoinType.Left)
{
var whereExp = DynamicCoreHelper.GetWhere(keyIsShortName_ValueIsType_Dictionary,onExpString);
var name=whereExp.Parameters.Last(it => it.Type == JoinType).Name;
var sql = this.QueryBuilder.GetExpressionValue(whereExp, ResolveExpressType.WhereMultiple).GetResultString();
return AddJoinInfo(JoinType, name, sql,type);
}
public ISugarQueryable<T> AddJoinInfo(Type JoinType, string shortName, string joinWhere, JoinType type = JoinType.Left) public ISugarQueryable<T> AddJoinInfo(Type JoinType, string shortName, string joinWhere, JoinType type = JoinType.Left)
{ {
this.Context.InitMappingInfo(JoinType); this.Context.InitMappingInfo(JoinType);

View File

@@ -63,8 +63,8 @@ namespace SqlSugar
ISugarQueryable<T> AddParameters(SugarParameter[] parameters); ISugarQueryable<T> AddParameters(SugarParameter[] parameters);
ISugarQueryable<T> AddParameters(List<SugarParameter> parameters); ISugarQueryable<T> AddParameters(List<SugarParameter> parameters);
ISugarQueryable<T> AddJoinInfo(string tableName, string shortName, string joinWhere, JoinType type = JoinType.Left); ISugarQueryable<T> AddJoinInfo(string tableName, string shortName, string joinWhere, JoinType type = JoinType.Left);
ISugarQueryable<T> AddJoinInfo(Type JoinType, string shortName, string joinWhere, JoinType type = JoinType.Left); ISugarQueryable<T> AddJoinInfo(Type JoinEntityType, string shortName, string joinWhere, JoinType type = JoinType.Left);
ISugarQueryable<T> AddJoinInfo(Type JoinEntityType, Dictionary<string, Type> keyIsShortName_ValueIsType_Dictionary, FormattableString onExpString, JoinType type = JoinType.Left);
/// <summary> /// <summary>
/// if a property that is not empty is a condition /// if a property that is not empty is a condition
/// </summary> /// </summary>