Add: Queryable.IncludesAllSecondLayer(exp)

This commit is contained in:
sunkaixuan
2023-03-27 18:26:41 +08:00
parent 211ca918fb
commit bce8b154b5
2 changed files with 39 additions and 0 deletions

View File

@@ -10,6 +10,11 @@ namespace SqlSugar
{
public partial class QueryableProvider<T> : QueryableAccessory, ISugarQueryable<T>
{
public ISugarQueryable<T> IncludesByExpression2<TReturn1, TReturn2>(Expression include1, Expression include2)
{
_Includes<T, TReturn1,TReturn2>(this.Context, include1,include2);
return this;
}
public ISugarQueryable<T> IncludesByExpression<TReturn1>(Expression include1)
{
_Includes<T, TReturn1>(this.Context, include1);
@@ -41,6 +46,38 @@ namespace SqlSugar
}
return this;
}
public ISugarQueryable<T> IncludesAllSecondLayer<TReturn1>(Expression<Func<T, TReturn1>> expression, params string[] ignoreProperyNameList)
{
this.Includes(expression);
var type = typeof(TReturn1);
if (type.FullName.IsCollectionsList())
{
type = type.GetGenericArguments()[0];
}
var navs = this.Context.EntityMaintenance.GetEntityInfo(type).Columns.Where(it => it.Navigat != null).ToList();
foreach (var item in navs)
{
if (ignoreProperyNameList != null && ignoreProperyNameList.Any(z => z.EqualCase(item.PropertyName)))
{
//future
}
else
{
var properyType = item.PropertyInfo.PropertyType;
var properyItemType = properyType;
if (properyType.FullName.IsCollectionsList())
{
properyItemType = properyType.GetGenericArguments()[0];
}
var exp = ExpressionBuilderHelper.CreateExpressionSelectField(type, item.PropertyName, properyType);
var method = this.GetType().GetMethods().Where(it => it.Name == "IncludesByExpression2")
.First()
.MakeGenericMethod(type, properyItemType);
method.Invoke(this, new object[] { expression, exp });
}
}
return this;
}
public ISugarQueryable<T> Includes<TReturn1>(Expression<Func<T, List<TReturn1>>> include1) { _Includes<T, TReturn1>(this.Context, include1); return this; }
public ISugarQueryable<T> Includes<TReturn1>(Expression<Func<T, TReturn1>> include1) { _Includes<T, TReturn1>(this.Context, include1); return this; }
public ISugarQueryable<T> Includes<TReturn1, TReturn2>(Expression<Func<T, TReturn1>> include1, Expression<Func<TReturn1, List<TReturn2>>> include2) { _Includes<T, TReturn1, TReturn2>(this.Context, include1, include2); return this; }

View File

@@ -14,8 +14,10 @@ namespace SqlSugar
public partial interface ISugarQueryable<T>
{
NavISugarQueryable<T> AsNavQueryable();
ISugarQueryable<T> IncludesByExpression2<TReturn1, TReturn2>(Expression include1, Expression include2);
ISugarQueryable<T> IncludesByExpression<TReturn1>(Expression include1);
ISugarQueryable<T> IncludesAllFirstLayer(params string[] ignoreProperyNameList);
ISugarQueryable<T> IncludesAllSecondLayer<TReturn1>(Expression<Func<T, TReturn1>> expression,params string[] ignoreProperyNameList);
ISugarQueryable<T> Includes<TReturn1>(Expression<Func<T, List<TReturn1>>> include1);
ISugarQueryable<T> Includes<TReturn1>(Expression<Func<T, TReturn1>> include1);
ISugarQueryable<T> Includes<TReturn1, TReturn2>(Expression<Func<T, List<TReturn1>>> include1, Expression<Func<TReturn1, List<TReturn2>>> include2);