mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2026-02-27 16:50:33 +08:00
Navigation supports auto-population
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@@ -9,6 +10,37 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
public partial class QueryableProvider<T> : QueryableAccessory, ISugarQueryable<T>
|
public partial class QueryableProvider<T> : QueryableAccessory, ISugarQueryable<T>
|
||||||
{
|
{
|
||||||
|
public ISugarQueryable<T> IncludesByExpression<TReturn1>(Expression include1)
|
||||||
|
{
|
||||||
|
_Includes<T, TReturn1>(this.Context, include1);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
public ISugarQueryable<T> IncludesAllFirstLayer(params string[] ignoreProperyNameList)
|
||||||
|
{
|
||||||
|
var navs=this.EntityInfo.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(typeof(T), item.PropertyName, properyType);
|
||||||
|
var method = this.GetType().GetMethods().Where(it => it.Name == "IncludesByExpression")
|
||||||
|
.First()
|
||||||
|
.MakeGenericMethod(properyItemType);
|
||||||
|
method.Invoke(this, new object[] { 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, 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>(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; }
|
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; }
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ namespace SqlSugar
|
|||||||
public partial interface ISugarQueryable<T>
|
public partial interface ISugarQueryable<T>
|
||||||
{
|
{
|
||||||
NavISugarQueryable<T> AsNavQueryable();
|
NavISugarQueryable<T> AsNavQueryable();
|
||||||
|
ISugarQueryable<T> IncludesByExpression<TReturn1>(Expression include1);
|
||||||
|
ISugarQueryable<T> IncludesAllFirstLayer(params string[] ignoreProperyNameList);
|
||||||
ISugarQueryable<T> Includes<TReturn1>(Expression<Func<T, List<TReturn1>>> include1);
|
ISugarQueryable<T> Includes<TReturn1>(Expression<Func<T, List<TReturn1>>> include1);
|
||||||
ISugarQueryable<T> Includes<TReturn1>(Expression<Func<T, 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);
|
ISugarQueryable<T> Includes<TReturn1, TReturn2>(Expression<Func<T, List<TReturn1>>> include1, Expression<Func<TReturn1, List<TReturn2>>> include2);
|
||||||
|
|||||||
@@ -75,6 +75,19 @@ namespace SqlSugar
|
|||||||
return Expression.Lambda<Func<T, object>>(Expression.MemberInit(
|
return Expression.Lambda<Func<T, object>>(Expression.MemberInit(
|
||||||
Expression.New(dynamicType.GetConstructor(Type.EmptyTypes)), bindings), sourceItem);
|
Expression.New(dynamicType.GetConstructor(Type.EmptyTypes)), bindings), sourceItem);
|
||||||
}
|
}
|
||||||
|
public static Expression CreateExpressionSelectField(Type classType, string propertyName, Type propertyType)
|
||||||
|
{
|
||||||
|
ParameterExpression parameter = Expression.Parameter(classType, "it");
|
||||||
|
|
||||||
|
// 创建属性表达式
|
||||||
|
PropertyInfo propertyInfo = classType.GetProperty(propertyName);
|
||||||
|
MemberExpression property = Expression.Property(parameter, propertyInfo);
|
||||||
|
|
||||||
|
// 创建Lambda表达式
|
||||||
|
Type funcType = typeof(Func<,>).MakeGenericType(classType, propertyType);
|
||||||
|
LambdaExpression lambda = Expression.Lambda(funcType, property, parameter);
|
||||||
|
return lambda;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
internal static class LinqRuntimeTypeBuilder
|
internal static class LinqRuntimeTypeBuilder
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user