예제 #1
0
 /// <summary>
 /// 转换表达式
 /// </summary>
 /// <param name="expression"></param>
 private void convertMemberAccess(MemberExpression expression)
 {
     //if (expression.Expression != null && typeof(ParameterExpression).IsAssignableFrom(expression.Expression.GetType()))
     if (expression.Expression != null && expression.Expression.NodeType == ExpressionType.Parameter)
     {
         string name = expression.Member.Name, sqlName = ConstantConverter.ConvertName(name);
         if (FirstMemberName == null)
         {
             FirstMemberName    = name;
             FirstMemberSqlName = sqlName;
         }
         SqlStream.SimpleWrite(sqlName);
         return;
     }
     whereExpression.ConvertMemberAccess(expression);
     if (whereExpression.Type != WhereExpression.ConvertType.Unknown)
     {
         if (whereExpression.Expression.NodeType == ExpressionType.Constant)
         {
             convertConstant(whereExpression.Expression.GetConstantValue());
         }
         else
         {
             throw new InvalidCastException("未知成员表达式类型 " + expression.Member.Name + " " + whereExpression.Expression.NodeType.ToString());
         }
     }
     else
     {
         throw new InvalidCastException("未知成员表达式 " + expression.Member.Name + " " + whereExpression.Type.ToString());
     }
 }
        /// <summary>
        /// 转换表达式
        /// </summary>
        /// <param name="expression"></param>
        private void convertMemberAccess(MemberExpression expression)
        {
            if (expression.Expression != null && typeof(ParameterExpression).IsAssignableFrom(expression.Expression.GetType()))
            {
                string name = expression.Member.Name, sqlName = ConstantConverter.ConvertName(name);
                if (FirstMemberName == null)
                {
                    FirstMemberName    = name;
                    FirstMemberSqlName = sqlName;
                }
                SqlStream.SimpleWriteNotNull(sqlName);
                return;
            }
            object value = null;

            if (expression.TryGetConstant(ref value))
            {
                convertConstant(value);
                return;
            }
            throw new InvalidCastException("未知成员表达式类型 " + expression.Expression.GetType().Name);
        }