Beispiel #1
0
        private static string ResolveParameterExpression(ParameterExpression expression)
        {
            var parameterType = (expression as ParameterExpression).Type;

            var typeMapping_parameterType = DbTypeMapping.TypeMapping(parameterType);

            if (typeMapping_parameterType.Equals(DbTypeMapping.List_UserType))
            {
                if (!types.Contains(parameterType))
                {
                    types.Add(parameterType);
                }

                return(null);
            }
            else if (typeMapping_parameterType.Equals(DbTypeMapping.UserType))
            {
                CreateJoin(parameterType.Name + "." + new ModelUtil(parameterType).PrimaryKeyPropertyName);

                if (!types.Contains(parameterType))
                {
                    types.Add(parameterType);
                }

                return((expression as ParameterExpression).Type.Name);
            }
            else
            {
                return(null);
            }
        }
Beispiel #2
0
        public List <TModel> SelectModels <TModel>(Expression expression)
        {
            LambdaTranslator.MappingDataSet = MappingDataSet;

            TranslatorResult res = LambdaTranslator.ResolveExpression(expression, true);


            List <RelationModel> relations = new List <RelationModel>();

            List <string> tables = new List <string>();

            //遍历所有涉及到的关系
            foreach (var type in res.Types)
            {
                if (DbTypeMapping.TypeMapping(type).Equals(DbTypeMapping.UserType))
                {
                    var rls = MappingDataSet.GetRelation(type.Name);
                    relations.Add(rls);

                    tables.Add(rls.TbName);
                }
                else if (DbTypeMapping.TypeMapping(type).Equals(DbTypeMapping.List_UserType))
                {
                    //建立新的查询,
                }
            }

            var selectSql = Select.From(tables);

            foreach (var r in relations)
            {
                foreach (var c in r.Columns)
                {
                    selectSql.AddColumns(r.TbName + "." + c.ColumnName + " as " + r.TbName + "_" + c.ColumnName);
                }
            }
            selectSql.SetWhere(res.GetWhere());

            string sql_str = selectSql.ToSql().ToString();
            var    dataSet = GetDataSet(selectSql.ToSql());

            var tabless = dataSet.Tables;

            return(null);
        }
Beispiel #3
0
        public static string ResolveMemberExpression(MemberExpression expression)
        {
            //展开成员表达式
            if (!expressionCatches.Keys.Contains(expression.ToString()))
            {
                var memberType = expression.Type;

                var typeMapping_rightType = DbTypeMapping.TypeMapping(memberType);

                if (typeMapping_rightType.Equals(DbTypeMapping.List_UserType))
                {
                    //如果成员表达式的右边是集合类型
                    if (!types.Contains(memberType))
                    {
                        types.Add(memberType);
                    }

                    expressionCatches.Add(expression.ToString(), null);
                    return(null);
                }
                else if (typeMapping_rightType.Equals(DbTypeMapping.UserType))
                {
                    //如果成员表达式的右边是用户类型

                    CreateJoin(memberType.Name + "." + new ModelUtil(memberType).PrimaryKeyPropertyName); //构造多关系连接

                    if (!types.Contains(memberType))
                    {
                        types.Add(memberType);
                    }

                    if (expression.Expression.NodeType == ExpressionType.Parameter)
                    {
                        ResolveParameterExpression(expression.Expression as ParameterExpression);
                    }
                    else if (expression.Expression.NodeType == ExpressionType.MemberAccess)
                    {
                        ResolveMemberExpression(expression.Expression as MemberExpression);
                    }

                    expressionCatches.Add(expression.ToString(), null);
                    return(null);
                }
                else
                {
                    //如果成员表达式的右边是值类型
                    var memberName = expression.Member.Name;

                    string RelationName = null;

                    if (expression.Expression.NodeType == ExpressionType.Parameter)
                    {
                        RelationName = ResolveParameterExpression(expression.Expression as ParameterExpression);
                    }
                    else if (expression.Expression.NodeType == ExpressionType.MemberAccess)
                    {
                        RelationName = (expression.Expression as MemberExpression).Type.Name;

                        ResolveMemberExpression(expression.Expression as MemberExpression);
                    }

                    expressionCatches.Add(expression.ToString(), RelationName + "." + memberName);
                    return(RelationName + "." + memberName);
                }
            }
            else
            {
                return(expressionCatches[expression.ToString()]);
            }
        }