mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-05-15 20:49:31 +08:00
Update exp to sql
This commit is contained in:
parent
6e41c03b9a
commit
18e1be83be
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -12,7 +12,7 @@ namespace SqlSugar
|
|||||||
#region Constructor
|
#region Constructor
|
||||||
public string shorName { get; set; }
|
public string shorName { get; set; }
|
||||||
public EntityInfo entityInfo;
|
public EntityInfo entityInfo;
|
||||||
|
public List<ExpressionItems> items;
|
||||||
public SqlSugarProvider context;
|
public SqlSugarProvider context;
|
||||||
public OneToOneNavgateExpressionN(SqlSugarProvider context)
|
public OneToOneNavgateExpressionN(SqlSugarProvider context)
|
||||||
{
|
{
|
||||||
@ -75,7 +75,6 @@ namespace SqlSugar
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region All one to one
|
#region All one to one
|
||||||
List<ExpressionItems> items;
|
|
||||||
private bool ValidateIsJoinMember(bool result, MemberExpression memberExp, Expression childExpression)
|
private bool ValidateIsJoinMember(bool result, MemberExpression memberExp, Expression childExpression)
|
||||||
{
|
{
|
||||||
if (childExpression != null && childExpression is MemberExpression)
|
if (childExpression != null && childExpression is MemberExpression)
|
||||||
@ -121,13 +120,6 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region One to one Last Method
|
|
||||||
private bool ValidateIsJoinAny(bool result, MemberExpression memberExp, Expression childExpression)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Helper
|
#region Helper
|
||||||
|
|
||||||
private static bool IsParameter(Expression child2Expression)
|
private static bool IsParameter(Expression child2Expression)
|
||||||
@ -146,31 +138,5 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
#endregion
|
#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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,9 @@
|
|||||||
<Compile Include="Enum\NavigatType.cs" />
|
<Compile Include="Enum\NavigatType.cs" />
|
||||||
<Compile Include="Enum\SugarActionType.cs" />
|
<Compile Include="Enum\SugarActionType.cs" />
|
||||||
<Compile Include="Entities\SugarConnection.cs" />
|
<Compile Include="Entities\SugarConnection.cs" />
|
||||||
|
<Compile Include="ExpressionsToSql\Common\ExpressionItems.cs" />
|
||||||
<Compile Include="ExpressionsToSql\Common\ExpressionOutParameter.cs" />
|
<Compile Include="ExpressionsToSql\Common\ExpressionOutParameter.cs" />
|
||||||
|
<Compile Include="ExpressionsToSql\ResolveItems\OneToManyNavgateExpressionN.cs" />
|
||||||
<Compile Include="ExpressionsToSql\ResolveItems\OneToManyNavgateExpression.cs" />
|
<Compile Include="ExpressionsToSql\ResolveItems\OneToManyNavgateExpression.cs" />
|
||||||
<Compile Include="ExpressionsToSql\ResolveItems\OneToOneNavgateExpressionN.cs" />
|
<Compile Include="ExpressionsToSql\ResolveItems\OneToOneNavgateExpressionN.cs" />
|
||||||
<Compile Include="ExpressionsToSql\ResolveItems\OneToOneNavgateExpression.cs" />
|
<Compile Include="ExpressionsToSql\ResolveItems\OneToOneNavgateExpression.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user