Browse Source

Update db.QueryableByObject

pull/33/head
sunkaixuan 1 year ago
parent
commit
68dc16a771
  1. 33
      Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryMethodInfo.cs
  2. 4
      Src/Asp.Net/SqlSugar/Abstract/SugarProvider/SqlSugarProvider.cs
  3. 4
      Src/Asp.Net/SqlSugar/Abstract/SugarProvider/SqlSugarScopeProvider.cs
  4. 1
      Src/Asp.Net/SqlSugar/Interface/ISqlSugarClient.cs
  5. 4
      Src/Asp.Net/SqlSugar/SqlSugarClient.cs
  6. 4
      Src/Asp.Net/SqlSugar/SqlSugarScope.cs
  7. 9
      Src/Asp.Net/SqlSugar/Utilities/CommonExtensions.cs

33
Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryMethodInfo.cs

@ -11,13 +11,42 @@ namespace SqlSugar
public SqlSugarProvider Context { get; internal set; }
public Type EntityType { get; set; }
#region Json 2 sql api
#endregion
#region Sql API
public QueryMethodInfo AS(string tableName)
{
string shortName = $"{tableName}_1";
var method = QueryableObj.GetType().GetMyMethod("AS", 2, typeof(string), typeof(string));
this.QueryableObj = method.Invoke(QueryableObj, new object[] { tableName, shortName });
return this;
}
public QueryMethodInfo AS(string tableName, string shortName)
{
var method = QueryableObj.GetType().GetMyMethod("AS", 2, typeof(string), typeof(string));
this.QueryableObj = method.Invoke(QueryableObj, new object[] { tableName, shortName });
return this;
}
public QueryMethodInfo OrderBy(string orderBySql)
{
var method = QueryableObj.GetType().GetMyMethod("OrderBy", 1, typeof(string));
this.QueryableObj = method.Invoke(QueryableObj, new object[] { orderBySql });
return this;
}
public QueryMethodInfo AddJoinInfo(string tableName, string shortName,string onWhere, JoinType type = JoinType.Left)
{
var method = QueryableObj.GetType().GetMyMethod("AddJoinInfo", 4, typeof(string),typeof(string),typeof(string),typeof(JoinType));
this.QueryableObj = method.Invoke(QueryableObj, new object[] { tableName,shortName,onWhere,type });
return this;
}
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));
this.QueryableObj = method.Invoke(QueryableObj, new object[] { this.Context.EntityMaintenance.GetTableName(joinEntityType), shortName, onWhere, type });
return this;
}
public QueryMethodInfo GroupBy(string groupBySql)
{
var method = QueryableObj.GetType().GetMyMethod("GroupBy", 1, typeof(string));
@ -71,6 +100,8 @@ namespace SqlSugar
return this;
}
#endregion
#region Result
public object ToPageList(int pageNumber, int pageSize)
{

4
Src/Asp.Net/SqlSugar/Abstract/SugarProvider/SqlSugarProvider.cs

@ -93,6 +93,10 @@ namespace SqlSugar
result.EntityType = entityType;
return result;
}
public QueryMethodInfo QueryableByObject(Type entityType, string shortName)
{
return this.QueryableByObject(entityType).AS(this.Context.EntityMaintenance.GetTableName(entityType),shortName);
}
/// <summary>
/// Get datebase time
/// </summary>

4
Src/Asp.Net/SqlSugar/Abstract/SugarProvider/SqlSugarScopeProvider.cs

@ -819,6 +819,10 @@ namespace SqlSugar
{
return ScopedContext.QueryableByObject(entityType);
}
public QueryMethodInfo QueryableByObject(Type entityType, string shortName)
{
return ScopedContext.QueryableByObject(entityType, shortName);
}
#endregion
}
}

1
Src/Asp.Net/SqlSugar/Interface/ISqlSugarClient.cs

@ -79,6 +79,7 @@ namespace SqlSugar
#endregion
#region Queryable
QueryMethodInfo QueryableByObject(Type entityType, string shortName);
QueryMethodInfo QueryableByObject(Type entityType);
ISugarQueryable<T> MasterQueryable<T>();
ISugarQueryable<T> SlaveQueryable<T>();

4
Src/Asp.Net/SqlSugar/SqlSugarClient.cs

@ -288,6 +288,10 @@ namespace SqlSugar
{
return this.Context.QueryableByObject(entityType);
}
public QueryMethodInfo QueryableByObject(Type entityType,string shortName)
{
return this.Context.QueryableByObject(entityType,shortName);
}
public ISugarQueryable<T> MasterQueryable<T>()
{
return this.Context.MasterQueryable<T>();

4
Src/Asp.Net/SqlSugar/SqlSugarScope.cs

@ -876,5 +876,9 @@ namespace SqlSugar
{
return ScopedContext.QueryableByObject(entityType);
}
public QueryMethodInfo QueryableByObject(Type entityType, string shortName)
{
return ScopedContext.QueryableByObject(entityType, shortName);
}
}
}

9
Src/Asp.Net/SqlSugar/Utilities/CommonExtensions.cs

@ -47,6 +47,15 @@ namespace SqlSugar
it.GetParameters()[1].ParameterType == parameterType2&&
it.GetParameters()[2].ParameterType == parameterType3);
}
public static MethodInfo GetMyMethod(this Type type, string name, int argCount, Type parameterType, Type parameterType2, Type parameterType3,Type parameterType4)
{
return type.GetMethods().Where(it => it.Name == name).FirstOrDefault(it =>
it.GetParameters().Length == argCount &&
it.GetParameters().First().ParameterType == parameterType &&
it.GetParameters()[1].ParameterType == parameterType2 &&
it.GetParameters()[2].ParameterType == parameterType3&&
it.GetParameters()[3].ParameterType == parameterType4);
}
public static List<T> ToList<T>(this T thisValue,Func<T,T> action) where T:class,new()
{
return new List<T> { thisValue };

Loading…
Cancel
Save