コード例 #1
0
        public static Dictionary <string, string> BuildColumn(Expression expression, Dictionary <string, object> param, string prefix, bool singleTable = true)
        {
            if (expression is LambdaExpression)
            {
                expression = (expression as LambdaExpression).Body;
            }
            var column = new Dictionary <string, string>();

            if (expression is MemberExpression)
            {
                var memberExpression = (expression as MemberExpression);
                var name             = memberExpression.Member.Name;
                var columnName       = EntityUtil.GetColumn(memberExpression.Expression.Type, f => f.CSharpName == name)?.ColumnName ?? name;
                if (!singleTable)
                {
                    var tableName = EntityUtil.GetTable(memberExpression.Expression.Type).TableName;
                    columnName = string.Format("{0}.{1}", tableName, columnName);
                }
                column.Add(name, columnName);
                return(column);
            }
            else
            {
                var name = string.Format("COLUMN0");
                if (expression is MemberExpression memberExpression)
                {
                    name = memberExpression.Member.Name;
                }
                var build = BuildExpression(expression, param, prefix, singleTable);
                column.Add(name, build);
                return(column);
            }
        }
コード例 #2
0
        public void SetName(MemberExpression expression)
        {
            var name       = expression.Member.Name;
            var columnName = EntityUtil.GetColumn(expression.Expression.Type, f => f.CSharpName == name)?.ColumnName ?? name;

            if (!_singleTable)
            {
                var tableName = EntityUtil.GetTable(expression.Expression.Type).TableName;
                columnName = string.Format("{0}.{1}", tableName, columnName);
            }
            _build.Append(columnName);
            _paramName = name;
        }
コード例 #3
0
        public static Dictionary <string, string> BuildColumns(Expression expression, Dictionary <string, object> param, bool singleTable = true)
        {
            var columns = new Dictionary <string, string>();

            if (expression is LambdaExpression)
            {
                expression = (expression as LambdaExpression).Body;
            }
            if (expression is MemberInitExpression)
            {
                var initExpression = (expression as MemberInitExpression);
                for (int i = 0; i < initExpression.Bindings.Count; i++)
                {
                    var        column   = string.Empty;
                    Expression argument = (initExpression.Bindings[i] as MemberAssignment).Expression;
                    if (argument is UnaryExpression)
                    {
                        argument = (argument as UnaryExpression).Operand;
                    }
                    if (argument is MethodCallExpression && (argument as MethodCallExpression).Method.DeclaringType == typeof(Convert))
                    {
                        column = GetValue((argument as MethodCallExpression).Arguments[0]).ToString();
                    }
                    else if (argument is ConstantExpression || (argument is MemberExpression && (argument as MemberExpression).Expression is ConstantExpression))
                    {
                        column = GetValue(argument).ToString();
                    }
                    else
                    {
                        column = BuildExpression(argument, param, singleTable);
                    }
                    var name = initExpression.Bindings[i].Member.Name;
                    columns.Add(name, column);
                }
            }
            else if (expression is NewExpression)
            {
                var newExpression = (expression as NewExpression);
                for (int i = 0; i < newExpression.Arguments.Count; i++)
                {
                    var columnName = string.Empty;
                    var argument   = newExpression.Arguments[i];
                    if (argument is MethodCallExpression && (argument as MethodCallExpression).Method.DeclaringType == typeof(Convert))
                    {
                        columnName = GetValue((argument as MethodCallExpression).Arguments[0]).ToString();
                    }
                    else if (argument is ConstantExpression || (argument is MemberExpression && (argument as MemberExpression).Expression is ConstantExpression))
                    {
                        columnName = GetValue(argument).ToString();
                    }
                    else
                    {
                        columnName = BuildExpression(argument, param, singleTable);
                    }
                    var name = newExpression.Members[i].Name;
                    columns.Add(name, columnName);
                }
            }
            else if (expression is MemberExpression)
            {
                var memberExpression = (expression as MemberExpression);
                var name             = memberExpression.Member.Name;
                var columnName       = EntityUtil.GetColumn(memberExpression.Expression.Type, f => f.CSharpName == name)?.ColumnName ?? name;
                if (!singleTable)
                {
                    var tableName = EntityUtil.GetTable(memberExpression.Expression.Type).TableName;
                    columnName = string.Format("{0}.{1}", tableName, columnName);
                }
                columns.Add(name, columnName);
            }
            else
            {
                var name       = string.Format("COLUMN0");
                var columnName = BuildExpression(expression, param, singleTable);
                columns.Add(name, columnName);
            }
            return(columns);
        }