Browse Source

Update exp to sql

pull/1/head
skx 4 years ago
parent
commit
47d9fe26b7
  1. 19
      Src/Asp.NetCore2/SqlSeverTest/SqlSeverTest/UnitTest/UQueryable.cs
  2. 17
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Common/ExpressionTool.cs
  3. 18
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MemberInitExpressionResolve.cs

19
Src/Asp.NetCore2/SqlSeverTest/SqlSeverTest/UnitTest/UQueryable.cs

@ -95,9 +95,28 @@ namespace OrmTest
a = it.a.Value
}).ToSql();
UValidate.Check(x.Key, "SELECT [a] AS [a] FROM [BoolTest2] ", "Queryable");
Db.CodeFirst.InitTables<UnitDecimal>();
Db.Queryable<UnitDecimal>().Select(it =>
new UnitDecimal2
{
x1 = it.x1 * it.x2
}).ToList();
}
public class UnitDecimal
{
public decimal x1 { get; set; }
public decimal x2 { get; set; }
}
public class UnitDecimal2 {
public decimal? x1 { get; set; }
}
/// <summary>
/// 系统用户表实体模型类
/// </summary>

17
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Common/ExpressionTool.cs

@ -59,7 +59,22 @@ namespace SqlSugar
else
return value;
}
public static Type GetMemberInfoType(MemberInfo member)
{
switch (member.MemberType)
{
case MemberTypes.Event:
return ((EventInfo)member).EventHandlerType;
case MemberTypes.Field:
return ((FieldInfo)member).FieldType;
case MemberTypes.Method:
return ((MethodInfo)member).ReturnType;
case MemberTypes.Property:
return ((PropertyInfo)member).PropertyType;
default:
return null;
}
}
public static bool IsLogicOperator(string operatorValue)
{
return operatorValue == "&&" || operatorValue == "||"||operatorValue == "AND" || operatorValue == "OR";

18
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MemberInitExpressionResolve.cs

@ -242,10 +242,28 @@ namespace SqlSugar
MemberAssignment memberAssignment = (MemberAssignment)binding;
var memberName = memberAssignment.Member.Name;
var item = memberAssignment.Expression;
if (IsNullable(item) && item is UnaryExpression)
{
var memtype = ExpressionTool.GetMemberInfoType(memberAssignment.Member);
if (IsNullable(memtype) && UtilMethods.GetUnderType(memtype) == UtilMethods.GetUnderType(item.Type))
{
item = (item as UnaryExpression).Operand;
}
}
ResolveNewExpressions(parameter, item, memberName);
}
}
private static bool IsNullable(Type memtype)
{
return memtype.Name == "Nullable`1";
}
private static bool IsNullable(Expression item)
{
return item.Type.Name == "Nullable`1";
}
//private bool IsSubMethod(MethodCallExpression express)
//{
// return SubTools.SubItemsConst.Any(it =>express.Object != null && express.Object.Type.Name == "Subqueryable`1");

Loading…
Cancel
Save