Browse Source

Update core

pull/17/head
sunkaixuan 3 years ago
parent
commit
130500b255
  1. 5
      Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/IncludesHelper.cs
  2. 1
      Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/NavigatManager.cs
  3. 60
      Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/BinaryExpressionResolve.cs
  4. 1
      Src/Asp.NetCore2/SqlSugar/Interface/IIncludes.cs

5
Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/IncludesHelper.cs

@ -45,7 +45,10 @@ namespace SqlSugar
if (this.QueryBuilder.Includes == null) this.QueryBuilder.Includes = new List<object>();
this.QueryBuilder.Includes.Add(navigat);
}
public NavISugarQueryable<T> AsNavQueryable()
{
return GetNavSugarQueryable();
}
private NavISugarQueryable<T> GetNavSugarQueryable()
{
var result= new NavQueryableProvider<T>();

1
Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/NavigatManager.cs

@ -269,6 +269,7 @@ namespace SqlSugar
var navEntity = navObjectNameColumnInfo.PropertyInfo.PropertyType.GetGenericArguments()[0];
var navEntityInfo = this.Context.EntityMaintenance.GetEntityInfo(navEntity);
var navColumn = navEntityInfo.Columns.FirstOrDefault(it => it.PropertyName == navObjectNameColumnInfo.Navigat.Name);
Check.ExceptionEasy(navColumn == null, $"{navEntityInfo.EntityName} not found {navObjectNameColumnInfo.Navigat.Name} ", $"实体 {navEntityInfo.EntityName} 未找到导航配置列 {navObjectNameColumnInfo.Navigat.Name} ");
//var navType = navObjectNamePropety.PropertyType;
var listItemPkColumn = listItemEntity.Columns.Where(it => it.IsPrimarykey).FirstOrDefault();
Check.ExceptionEasy(listItemPkColumn == null, listItemEntity.EntityName + " not primary key", listItemEntity.EntityName + "没有主键");

60
Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/BinaryExpressionResolve.cs

@ -3,6 +3,8 @@ using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Text.RegularExpressions;
namespace SqlSugar
{
public class BinaryExpressionResolve : BaseResolve
@ -26,6 +28,13 @@ namespace SqlSugar
{
var expression = this.Expression as BinaryExpression;
var operatorValue = parameter.OperatorValue = ExpressionTool.GetOperator(expression.NodeType);
if (IsGroupSubquery(expression.Right,operatorValue))
{
InSubGroupBy(expression);
return;
}
var isEqual = expression.NodeType == ExpressionType.Equal;
var isComparisonOperator = ExpressionTool.IsComparisonOperator(expression);
base.ExactExpression = expression;
@ -88,5 +97,56 @@ namespace SqlSugar
base.Context.Result.Append(" " + ExpressionConst.ExpressionReplace + parameter.BaseParameter.Index + " ");
}
}
private void InSubGroupBy(BinaryExpression expression)
{
var leftSql = GetNewExpressionValue(expression.Left);
var rightExpression = expression.Right as MethodCallExpression;
var selector = GetNewExpressionValue(rightExpression.Arguments[0]);
var rightSql = GetNewExpressionValue(rightExpression.Object).Replace("SELECT FROM", $"SELECT {selector} FROM");
if (this.Context.IsSingle&&this.Context.SingleTableNameSubqueryShortName==null)
{
var leftExp = expression.Left;
if (leftExp is UnaryExpression)
{
leftExp = (leftExp as UnaryExpression).Operand;
}
var p = (leftExp as MemberExpression);
this.Context.SingleTableNameSubqueryShortName=p.Expression.ToString();
}
base.Context.Result.Append($" {leftSql} in ({rightSql}) ");
}
private bool IsGroupSubquery(Expression rightExpression, string operatorValue)
{
if (operatorValue != "=")
{
return false;
}
if (rightExpression == null)
{
return false;
}
if ((rightExpression is MethodCallExpression) == false)
{
return false;
}
var method = (rightExpression as MethodCallExpression);
if (method.Method.Name != "Select")
{
return false;
}
var methodString = method.ToString();
if (methodString.IndexOf("GroupBy(")<=0)
{
return false;
}
if (Regex.Matches(methodString, @"Subqueryable\(").Count!=1)
{
return false;
}
return true;
}
}
}

1
Src/Asp.NetCore2/SqlSugar/Interface/IIncludes.cs

@ -13,6 +13,7 @@ namespace SqlSugar
/// <typeparam name="T"></typeparam>
public partial interface ISugarQueryable<T>
{
NavISugarQueryable<T> AsNavQueryable();
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);

Loading…
Cancel
Save