Browse Source

Update exp to sql

pull/18/head
sunkaixuan 3 years ago
parent
commit
18e1be83be
  1. 34
      Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionItems.cs
  2. 106
      Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/OneToManyNavgateExpressionN.cs
  3. 36
      Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/OneToOneNavgateExpressionN.cs
  4. 2
      Src/Asp.Net/SqlSugar/SqlSugar.csproj

34
Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionItems.cs

@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace SqlSugar
{
internal class ExpressionItems
{
/// <summary>
/// 0 memeber, 2 method ,3 class
/// </summary>
public int Type { get; set; }
public EntityInfo ParentEntityInfo { get; set; }
public EntityInfo ThisEntityInfo { get; set; }
public Expression Expression { get; set; }
public Navigate Nav
{
get
{
if (Expression is MemberExpression)
{
var name = (Expression as MemberExpression).Member.Name;
var navColumn = ParentEntityInfo.Columns.FirstOrDefault(it => it.PropertyName == name);
return navColumn == null ? null : navColumn.Navigat;
}
return null;
}
}
}
}

106
Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/OneToManyNavgateExpressionN.cs

@ -0,0 +1,106 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace SqlSugar
{
internal class OneToManyNavgateExpressionN
{
private SqlSugarProvider context;
public OneToManyNavgateExpressionN(SqlSugarProvider context, MethodCallExpressionResolve methodCallExpressionResolve)
{
this.context = context;
}
internal bool IsNavgate(Expression expression)
{
var result = false;
var exp = expression;
if (exp is UnaryExpression)
{
exp = (exp as UnaryExpression).Operand;
}
if (exp is MethodCallExpression)
{
var memberExp=exp as MethodCallExpression;
if (memberExp.Method.Name.IsIn("Any","Count") && memberExp.Arguments.Count>0 && memberExp.Arguments[0] is MemberExpression )
{
result = ValidateNav(result, memberExp.Arguments[0] as MemberExpression, memberExp.Arguments[0]);
if (memberExp.Arguments.Count > 1)
{
}
}
}
return result;
}
private string GetWhereSql(MethodCallExpression memberExp)
{
return null;
}
private bool ValidateNav(bool result, MemberExpression memberExp, Expression childExpression)
{
if (childExpression != null && childExpression is MemberExpression)
{
result = ValidateIsJoinMember(result,memberExp, childExpression);
}
return result;
}
List<ExpressionItems> items;
private bool ValidateIsJoinMember(bool result, MemberExpression memberExp, Expression childExpression)
{
if (childExpression != null && childExpression is MemberExpression)
{
var oldChildExpression = childExpression;
var child2Expression = (childExpression as MemberExpression).Expression;
if (child2Expression == null || (child2Expression is ConstantExpression))
{
return false;
}
items = new List<ExpressionItems>();
items.Add(new ExpressionItems() { Type = 1, Expression = memberExp, ParentEntityInfo = this.context.EntityMaintenance.GetEntityInfo(oldChildExpression.Type) });
items.Add(new ExpressionItems() { Type = 2, Expression = oldChildExpression, ThisEntityInfo = this.context.EntityMaintenance.GetEntityInfo(oldChildExpression.Type), ParentEntityInfo = this.context.EntityMaintenance.GetEntityInfo(child2Expression.Type) });
if (items.Any(it => it.Type == 2 && it.Nav == null))
{
return false;
}
while (child2Expression != null)
{
if (IsClass(child2Expression))
{
items.Add(new ExpressionItems() { Type = 2, Expression = child2Expression, ThisEntityInfo = this.context.EntityMaintenance.GetEntityInfo(child2Expression.Type), ParentEntityInfo = this.context.EntityMaintenance.GetEntityInfo(GetMemberExpression(child2Expression).Type) });
child2Expression = GetMemberExpression(child2Expression);
}
else if (IsParameter(child2Expression))
{
shorName = child2Expression.ToString();
entityInfo = this.context.EntityMaintenance.GetEntityInfo(child2Expression.Type);
break;
}
else
{
break;
}
}
if (!items.Any(it => it.Type == 2 && it.Nav == null))
{
return true;
}
}
return result;
}
internal object GetSql()
{
throw new NotImplementedException();
}
}
}

36
Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/OneToOneNavgateExpressionN.cs

@ -12,7 +12,7 @@ namespace SqlSugar
#region Constructor
public string shorName { get; set; }
public EntityInfo entityInfo;
public List<ExpressionItems> items;
public SqlSugarProvider context;
public OneToOneNavgateExpressionN(SqlSugarProvider context)
{
@ -75,7 +75,6 @@ namespace SqlSugar
#endregion
#region All one to one
List<ExpressionItems> items;
private bool ValidateIsJoinMember(bool result, MemberExpression memberExp, Expression childExpression)
{
if (childExpression != null && childExpression is MemberExpression)
@ -121,13 +120,6 @@ namespace SqlSugar
}
#endregion
#region One to one Last Method
private bool ValidateIsJoinAny(bool result, MemberExpression memberExp, Expression childExpression)
{
return false;
}
#endregion
#region Helper
private static bool IsParameter(Expression child2Expression)
@ -146,31 +138,5 @@ namespace SqlSugar
}
#endregion
#region Entities
internal class ExpressionItems
{
/// <summary>
/// 0 memeber, 2 method ,3 class
/// </summary>
public int Type { get; set; }
public EntityInfo ParentEntityInfo { get; set; }
public EntityInfo ThisEntityInfo { get; set; }
public Expression Expression { get; set; }
public Navigate Nav
{
get
{
if (Expression is MemberExpression)
{
var name=(Expression as MemberExpression).Member.Name;
var navColumn = ParentEntityInfo.Columns.FirstOrDefault(it => it.PropertyName == name);
return navColumn==null?null:navColumn.Navigat;
}
return null;
}
}
}
#endregion
}
}

2
Src/Asp.Net/SqlSugar/SqlSugar.csproj

@ -107,7 +107,9 @@
<Compile Include="Enum\NavigatType.cs" />
<Compile Include="Enum\SugarActionType.cs" />
<Compile Include="Entities\SugarConnection.cs" />
<Compile Include="ExpressionsToSql\Common\ExpressionItems.cs" />
<Compile Include="ExpressionsToSql\Common\ExpressionOutParameter.cs" />
<Compile Include="ExpressionsToSql\ResolveItems\OneToManyNavgateExpressionN.cs" />
<Compile Include="ExpressionsToSql\ResolveItems\OneToManyNavgateExpression.cs" />
<Compile Include="ExpressionsToSql\ResolveItems\OneToOneNavgateExpressionN.cs" />
<Compile Include="ExpressionsToSql\ResolveItems\OneToOneNavgateExpression.cs" />

Loading…
Cancel
Save