public IMappingObjectExpression ToNewObjectExpression(DbSqlQueryExpression sqlQuery, DbTable table)
        {
            MappingObjectExpression newMoe = new MappingObjectExpression(this.ConstructorDescriptor);

            foreach (var kv in this.MappingConstructorParameters)
            {
                ParameterInfo pi  = kv.Key;
                DbExpression  exp = kv.Value;

                DbColumnAccessExpression cae = null;
                cae = MappingObjectExpressionHelper.ParseColumnAccessExpression(sqlQuery, table, exp, pi.Name);

                newMoe.AddMappingConstructorParameter(pi, cae);
            }

            foreach (var kv in this.ComplexConstructorParameters)
            {
                ParameterInfo            pi  = kv.Key;
                IMappingObjectExpression val = kv.Value;

                IMappingObjectExpression complexMappingMember = val.ToNewObjectExpression(sqlQuery, table);
                newMoe.AddComplexConstructorParameter(pi, complexMappingMember);
            }

            foreach (var kv in this.MappingMembers)
            {
                MemberInfo   member = kv.Key;
                DbExpression exp    = kv.Value;

                DbColumnAccessExpression cae = null;
                cae = MappingObjectExpressionHelper.ParseColumnAccessExpression(sqlQuery, table, exp, member.Name);

                newMoe.AddMappingMemberExpression(member, cae);

                if (exp == this.PrimaryKey)
                {
                    newMoe.PrimaryKey = cae;
                    if (this.NullChecking == this.PrimaryKey)
                    {
                        newMoe.NullChecking = cae;
                    }
                }
            }

            foreach (var kv in this.ComplexMembers)
            {
                MemberInfo member            = kv.Key;
                IMappingObjectExpression val = kv.Value;

                IMappingObjectExpression complexMappingMember = val.ToNewObjectExpression(sqlQuery, table);
                newMoe.AddComplexMemberExpression(member, complexMappingMember);
            }

            if (newMoe.NullChecking == null)
            {
                newMoe.NullChecking = MappingObjectExpressionHelper.TryGetOrAddNullChecking(sqlQuery, table, this.NullChecking);
            }

            return(newMoe);
        }
        protected override IMappingObjectExpression VisitNew(NewExpression exp)
        {
            IMappingObjectExpression result = new MappingObjectExpression(exp.Constructor);

            ParameterInfo[] parames = exp.Constructor.GetParameters();
            for (int i = 0; i < parames.Length; i++)
            {
                ParameterInfo pi     = parames[i];
                Expression    argExp = exp.Arguments[i];
                if (Utils.IsMapType(pi.ParameterType))
                {
                    DbExpression dbExpression = this.VisistExpression(argExp);
                    result.AddConstructorParameter(pi, dbExpression);
                }
                else
                {
                    IMappingObjectExpression subResult = this.Visit(argExp);
                    result.AddConstructorEntityParameter(pi, subResult);
                }
            }

            return(result);
        }
Exemple #3
0
        public IMappingObjectExpression ToNewObjectExpression(DbSqlQueryExpression sqlQuery, DbTable table)
        {
            List <DbColumnSegment>  columnList     = sqlQuery.ColumnSegments;
            MappingObjectExpression moe            = new MappingObjectExpression(this.ConstructorDescriptor);
            MappingObjectExpression mappingMembers = this;

            foreach (var kv in this.ConstructorParameters)
            {
                ParameterInfo pi  = kv.Key;
                DbExpression  exp = kv.Value;

                DbColumnAccessExpression cae = null;
                cae = MappingObjectExpressionHelper.ParseColumnAccessExpression(sqlQuery, table, exp, pi.Name);

                moe.AddConstructorParameter(pi, cae);
            }

            foreach (var kv in mappingMembers.ConstructorEntityParameters)
            {
                ParameterInfo            pi  = kv.Key;
                IMappingObjectExpression val = kv.Value;

                IMappingObjectExpression navMappingMember = val.ToNewObjectExpression(sqlQuery, table);
                moe.AddConstructorEntityParameter(pi, navMappingMember);
            }

            foreach (var kv in mappingMembers.SelectedMembers)
            {
                MemberInfo   member = kv.Key;
                DbExpression exp    = kv.Value;

                DbColumnAccessExpression cae = null;
                cae = MappingObjectExpressionHelper.ParseColumnAccessExpression(sqlQuery, table, exp, member.Name);

                moe.AddMemberExpression(member, cae);

                if (exp == this.PrimaryKey)
                {
                    moe.PrimaryKey = cae;
                    if (this.NullChecking == this.PrimaryKey)
                    {
                        moe.NullChecking = cae;
                    }
                }
            }

            foreach (var kv in mappingMembers.SubResultEntities)
            {
                MemberInfo member            = kv.Key;
                IMappingObjectExpression val = kv.Value;

                IMappingObjectExpression navMappingMember = val.ToNewObjectExpression(sqlQuery, table);
                moe.AddNavMemberExpression(member, navMappingMember);
            }

            if (moe.NullChecking == null)
            {
                moe.NullChecking = MappingObjectExpressionHelper.TryGetOrAddNullChecking(sqlQuery, table, this.NullChecking);
            }

            return(moe);
        }
Exemple #4
0
        public IObjectActivatorCreator GenarateObjectActivatorCreator(DbSqlQueryExpression sqlQuery)
        {
            List <DbColumnSegment>  columnList     = sqlQuery.ColumnSegments;
            MappingEntity           mappingEntity  = new MappingEntity(this.ConstructorDescriptor);
            MappingObjectExpression mappingMembers = this;

            foreach (var kv in this.ConstructorParameters)
            {
                ParameterInfo pi  = kv.Key;
                DbExpression  exp = kv.Value;

                int ordinal;
                ordinal = MappingObjectExpressionHelper.TryGetOrAddColumn(sqlQuery, exp, pi.Name).Value;

                if (exp == this.NullChecking)
                {
                    mappingEntity.CheckNullOrdinal = ordinal;
                }

                mappingEntity.ConstructorParameters.Add(pi, ordinal);
            }

            foreach (var kv in mappingMembers.ConstructorEntityParameters)
            {
                ParameterInfo            pi  = kv.Key;
                IMappingObjectExpression val = kv.Value;

                IObjectActivatorCreator navMappingMember = val.GenarateObjectActivatorCreator(sqlQuery);
                mappingEntity.ConstructorEntityParameters.Add(pi, navMappingMember);
            }

            foreach (var kv in mappingMembers.SelectedMembers)
            {
                MemberInfo   member = kv.Key;
                DbExpression exp    = kv.Value;

                int ordinal;
                ordinal = MappingObjectExpressionHelper.TryGetOrAddColumn(sqlQuery, exp, member.Name).Value;

                if (exp == this.NullChecking)
                {
                    mappingEntity.CheckNullOrdinal = ordinal;
                }

                mappingEntity.Members.Add(member, ordinal);
            }

            foreach (var kv in mappingMembers.SubResultEntities)
            {
                MemberInfo member            = kv.Key;
                IMappingObjectExpression val = kv.Value;

                IObjectActivatorCreator navMappingMember = val.GenarateObjectActivatorCreator(sqlQuery);
                mappingEntity.EntityMembers.Add(kv.Key, navMappingMember);
            }

            if (mappingEntity.CheckNullOrdinal == null)
            {
                mappingEntity.CheckNullOrdinal = MappingObjectExpressionHelper.TryGetOrAddColumn(sqlQuery, this.NullChecking);
            }

            return(mappingEntity);
        }