Browse Source

Synchronization code

pull/36/head
sunkaixuan 1 year ago
parent
commit
aad531c46a
  1. 49
      Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/Includes.cs
  2. 38
      Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/IncludesHelper.cs
  3. 3
      Src/Asp.Net/SqlSugar/Interface/IIncludes.cs

49
Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/Includes.cs

@ -21,6 +21,16 @@ namespace SqlSugar
_Includes<T, TReturn1, TReturn2, TReturn3>(this.Context, include1, include2, include3);
return this;
}
public ISugarQueryable<T> IncludesByExpression4<TReturn1, TReturn2, TReturn3, TReturn4>(Expression include1, Expression include2, Expression include3, Expression include4)
{
_Includes<T, TReturn1, TReturn2, TReturn3, TReturn4>(this.Context, include1, include2, include3, include4);
return this;
}
public ISugarQueryable<T> IncludesByExpression5<TReturn1, TReturn2, TReturn3, TReturn4, TReturn5>(Expression include1, Expression include2, Expression include3, Expression include4, Expression include5)
{
_Includes<T, TReturn1, TReturn2, TReturn3, TReturn4, TReturn5>(this.Context, include1, include2, include3, include4, include5);
return this;
}
public ISugarQueryable<T> IncludesByExpression<TReturn1>(Expression include1)
{
_Includes<T, TReturn1>(this.Context, include1);
@ -56,7 +66,44 @@ namespace SqlSugar
method.MakeGenericMethod(types.ToArray()).Invoke(this, parametres.Cast<object>().ToArray());
return this;
}
public ISugarQueryable<T> IncludesByNameString(string navMemberName, string thenNavMemberName2, string thenNavMemberName3, string thenNavMemberName4)
{
var method = this.GetType().GetMethods().Where(it => it.Name == "IncludesByExpression4")
.First();
List<Expression> parametres = new List<Expression>();
List<Type> types = new List<Type>();
var entityInfo = this.EntityInfo;
method = GetIncludesByNameStringMethod(types, navMemberName, method, parametres, entityInfo);
//var navFirst = GetNavColumnInfo(navMemberName, entityInfo);
var entityInfo2 = this.Context.EntityMaintenance.GetEntityInfo(types.Last());
method = GetIncludesByNameStringMethod(types, thenNavMemberName2, method, parametres, entityInfo2);
var entityInfo3 = this.Context.EntityMaintenance.GetEntityInfo(types.Last());
method = GetIncludesByNameStringMethod(types, thenNavMemberName3, method, parametres, entityInfo3);
var entityInfo4 = this.Context.EntityMaintenance.GetEntityInfo(types.Last());
method = GetIncludesByNameStringMethod(types, thenNavMemberName4, method, parametres, entityInfo4);
method.MakeGenericMethod(types.ToArray()).Invoke(this, parametres.Cast<object>().ToArray());
return this;
}
public ISugarQueryable<T> IncludesByNameString(string navMemberName, string thenNavMemberName2, string thenNavMemberName3, string thenNavMemberName4, string thenNavMemberName5)
{
var method = this.GetType().GetMethods().Where(it => it.Name == "IncludesByExpression5")
.First();
List<Expression> parametres = new List<Expression>();
List<Type> types = new List<Type>();
var entityInfo = this.EntityInfo;
method = GetIncludesByNameStringMethod(types, navMemberName, method, parametres, entityInfo);
//var navFirst = GetNavColumnInfo(navMemberName, entityInfo);
var entityInfo2 = this.Context.EntityMaintenance.GetEntityInfo(types.Last());
method = GetIncludesByNameStringMethod(types, thenNavMemberName2, method, parametres, entityInfo2);
var entityInfo3 = this.Context.EntityMaintenance.GetEntityInfo(types.Last());
method = GetIncludesByNameStringMethod(types, thenNavMemberName3, method, parametres, entityInfo3);
var entityInfo4 = this.Context.EntityMaintenance.GetEntityInfo(types.Last());
method = GetIncludesByNameStringMethod(types, thenNavMemberName4, method, parametres, entityInfo4);
var entityInfo5 = this.Context.EntityMaintenance.GetEntityInfo(types.Last());
method = GetIncludesByNameStringMethod(types, thenNavMemberName5, method, parametres, entityInfo5);
method.MakeGenericMethod(types.ToArray()).Invoke(this, parametres.Cast<object>().ToArray());
return this;
}
private static MethodInfo GetIncludesByNameStringMethod(List<Type> types,string navMemberName, MethodInfo method, List<Expression> parametres, EntityInfo entityInfo)
{
var navFirst = GetNavColumnInfo(navMemberName, entityInfo);

38
Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/IncludesHelper.cs

@ -51,6 +51,44 @@ namespace SqlSugar
if (this.QueryBuilder.Includes == null) this.QueryBuilder.Includes = new List<object>();
this.QueryBuilder.Includes.Add(navigat);
}
private void _Includes<T1, TReturn1, TReturn2, TReturn3, TReturn4>(SqlSugarProvider context, params Expression[] expressions)
{
Func<ISugarQueryable<object>, List<object>> SelectR1 = it => it.Select<TReturn1>().ToList().Select(x => x as object).ToList();
Func<ISugarQueryable<object>, List<object>> SelectR2 = it => it.Select<TReturn2>().ToList().Select(x => x as object).ToList();
Func<ISugarQueryable<object>, List<object>> SelectR3 = it => it.Select<TReturn3>().ToList().Select(x => x as object).ToList();
Func<ISugarQueryable<object>, List<object>> SelectR4 = it => it.Select<TReturn4>().ToList().Select(x => x as object).ToList();
var navigat = new NavigatManager<T>();
navigat.SelectR1 = SelectR1;
navigat.SelectR2 = SelectR2;
navigat.SelectR3 = SelectR3;
navigat.SelectR4 = SelectR4;
navigat.Expressions = expressions;
navigat.IsCrossQueryWithAttr = this.QueryBuilder.IsCrossQueryWithAttr;
navigat.CrossQueryItems = this.QueryBuilder.CrossQueryItems;
navigat.Context = this.Context;
if (this.QueryBuilder.Includes == null) this.QueryBuilder.Includes = new List<object>();
this.QueryBuilder.Includes.Add(navigat);
}
private void _Includes<T1, TReturn1, TReturn2, TReturn3, TReturn4, TReturn5>(SqlSugarProvider context, params Expression[] expressions)
{
Func<ISugarQueryable<object>, List<object>> SelectR1 = it => it.Select<TReturn1>().ToList().Select(x => x as object).ToList();
Func<ISugarQueryable<object>, List<object>> SelectR2 = it => it.Select<TReturn2>().ToList().Select(x => x as object).ToList();
Func<ISugarQueryable<object>, List<object>> SelectR3 = it => it.Select<TReturn3>().ToList().Select(x => x as object).ToList();
Func<ISugarQueryable<object>, List<object>> SelectR4 = it => it.Select<TReturn4>().ToList().Select(x => x as object).ToList();
Func<ISugarQueryable<object>, List<object>> SelectR5 = it => it.Select<TReturn5>().ToList().Select(x => x as object).ToList();
var navigat = new NavigatManager<T>();
navigat.SelectR1 = SelectR1;
navigat.SelectR2 = SelectR2;
navigat.SelectR3 = SelectR3;
navigat.SelectR4 = SelectR4;
navigat.SelectR5 = SelectR5;
navigat.Expressions = expressions;
navigat.IsCrossQueryWithAttr = this.QueryBuilder.IsCrossQueryWithAttr;
navigat.CrossQueryItems = this.QueryBuilder.CrossQueryItems;
navigat.Context = this.Context;
if (this.QueryBuilder.Includes == null) this.QueryBuilder.Includes = new List<object>();
this.QueryBuilder.Includes.Add(navigat);
}
public NavISugarQueryable<T> AsNavQueryable()
{
return GetNavSugarQueryable();

3
Src/Asp.Net/SqlSugar/Interface/IIncludes.cs

@ -18,6 +18,9 @@ namespace SqlSugar
ISugarQueryable<T> IncludesByExpression<TReturn1>(Expression include1);
ISugarQueryable<T> IncludesByNameString(string navMemberName);
ISugarQueryable<T> IncludesByNameString(string navMemberName,string thenNavMemberName2);
ISugarQueryable<T> IncludesByNameString(string navMemberName, string thenNavMemberName2, string thenNavMemberName3);
ISugarQueryable<T> IncludesByNameString(string navMemberName, string thenNavMemberName2, string thenNavMemberName3, string thenNavMemberName4);
ISugarQueryable<T> IncludesByNameString(string navMemberName, string thenNavMemberName2, string thenNavMemberName3, string thenNavMemberName4,string thenNavMemberName5);
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);

Loading…
Cancel
Save