示例#1
0
        public override IQueryState Accept(IncludeExpression exp)
        {
            ComplexObjectModel owner = (ComplexObjectModel)this.QueryModel.ResultModel;
            owner.Include(exp.NavigationNode, this.QueryModel, false);

            return this;
        }
示例#2
0
        public override JoinQueryResult Visit(RootQueryExpression exp)
        {
            Type           type           = exp.ElementType;
            TypeDescriptor typeDescriptor = EntityTypeContainer.GetDescriptor(type);

            string  explicitTableName = exp.ExplicitTable;
            DbTable dbTable           = typeDescriptor.Table;

            if (explicitTableName != null)
            {
                dbTable = new DbTable(explicitTableName, dbTable.Schema);
            }
            string alias = this._queryModel.GenerateUniqueTableAlias(dbTable.Name);

            DbTableSegment tableSeg = CreateTableSegment(dbTable, alias, exp.Lock);

            DbTable            aliasTable = new DbTable(alias);
            ComplexObjectModel model      = typeDescriptor.GenObjectModel(aliasTable);

            //TODO 解析 on 条件表达式
            var          scopeParameters = this._scopeParameters.Clone(this._conditionExpression.Parameters.Last(), model);
            DbExpression condition       = GeneralExpressionParser.Parse(this._conditionExpression, scopeParameters, this._queryModel.ScopeTables);

            DbJoinTableExpression joinTable = new DbJoinTableExpression(this._joinType.AsDbJoinType(), tableSeg, condition);

            JoinQueryResult result = new JoinQueryResult();

            result.ResultModel = model;
            result.JoinTable   = joinTable;

            return(result);
        }
        public ActionResult Edit(Guid id)
        {
            var recipe = Recipes[id];

            return(View(ComplexObjectModel.For(recipe, o => o
                                               .For <Recipe>(c => c
                                                             .ReadOnly(r => r.Id)
                                                             .ReadOnly(r => r.CreatedTime)
                                                             .ReadOnly(r => r.UpdatedTime)
                                                             )
                                               )));
        }
示例#4
0
        public override MappingData GenerateMappingData()
        {
            ComplexObjectModel complexObjectModel = this.QueryModel.ResultModel as ComplexObjectModel;

            if (complexObjectModel == null)
            {
                return(base.GenerateMappingData());
            }

            if (complexObjectModel.HasMany())
            {
                return(base.AsSubQueryState().GenerateMappingData());
            }

            return(base.GenerateMappingData());
        }
示例#5
0
        internal ComplexObjectModel GenObjectModel(DbTable table)
        {
            ComplexObjectModel model = new ComplexObjectModel(this.Definition.Type);

            foreach (PrimitivePropertyDescriptor propertyDescriptor in this.PrimitivePropertyDescriptors)
            {
                DbColumnAccessExpression columnAccessExpression = new DbColumnAccessExpression(table, propertyDescriptor.Column);
                model.AddPrimitiveMember(propertyDescriptor.Property, columnAccessExpression);

                if (propertyDescriptor.IsPrimaryKey)
                {
                    model.PrimaryKey = columnAccessExpression;
                }
            }

            return(model);
        }
示例#6
0
        public virtual QueryModel CreateNewQueryModel(LambdaExpression selector)
        {
            QueryModel newQueryModel = this._queryModel.Clone();

            ComplexObjectModel complexObjectModel = this._queryModel.ResultModel as ComplexObjectModel;

            if (complexObjectModel != null)
            {
                complexObjectModel.SetupFilters(this._queryModel.IgnoreFilters);
            }

            ScopeParameterDictionary scopeParameters = this._queryModel.ScopeParameters.Clone(selector.Parameters[0], this._queryModel.ResultModel);
            IObjectModel             newResultModel  = SelectorResolver.Resolve(selector, scopeParameters, this._queryModel.ScopeTables);

            newQueryModel.ResultModel = newResultModel;

            return(newQueryModel);
        }
示例#7
0
        public virtual MappingData GenerateMappingData()
        {
            MappingData data = new MappingData();

            ComplexObjectModel complexObjectModel = this._queryModel.ResultModel as ComplexObjectModel;

            if (complexObjectModel != null)
            {
                complexObjectModel.SetupCollection(this._queryModel);
            }

            DbSqlQueryExpression sqlQuery = this.CreateSqlQuery();

            var objectActivatorCreator = this._queryModel.ResultModel.GenarateObjectActivatorCreator(sqlQuery);

            objectActivatorCreator.IsRoot = true;

            data.SqlQuery = sqlQuery;
            data.ObjectActivatorCreator = objectActivatorCreator;

            return(data);
        }
示例#8
0
        static QueryModel CreateQueryModel(RootQueryExpression rootQueryExp, ScopeParameterDictionary scopeParameters, StringSet scopeTables, Func <string, string> tableAliasGenerator)
        {
            Type entityType = rootQueryExp.ElementType;

            if (entityType.IsAbstract || entityType.IsInterface)
            {
                throw new ArgumentException("The type of input can not be abstract class or interface.");
            }

            QueryModel queryModel = new QueryModel(scopeParameters, scopeTables);

            TypeDescriptor typeDescriptor = EntityTypeContainer.GetDescriptor(entityType);

            DbTable dbTable = typeDescriptor.GenDbTable(rootQueryExp.ExplicitTable);
            string  alias   = null;

            if (tableAliasGenerator != null)
            {
                alias = tableAliasGenerator(dbTable.Name);
            }
            else
            {
                alias = queryModel.GenerateUniqueTableAlias(dbTable.Name);
            }

            queryModel.FromTable = CreateRootTable(dbTable, alias, rootQueryExp.Lock);

            DbTable            aliasTable = new DbTable(alias);
            ComplexObjectModel model      = typeDescriptor.GenObjectModel(aliasTable);

            model.DependentTable = queryModel.FromTable;

            queryModel.ResultModel = model;

            ParseFilters(queryModel, typeDescriptor.Definition.Filters, rootQueryExp.ContextFilters);

            return(queryModel);
        }
示例#9
0
        static QueryModel CreateQueryModel(Type type, string explicitTableName, LockType lockType, ScopeParameterDictionary scopeParameters, StringSet scopeTables)
        {
            if (type.IsAbstract || type.IsInterface)
                throw new ArgumentException("The type of input can not be abstract class or interface.");

            QueryModel queryModel = new QueryModel(scopeParameters, scopeTables);

            TypeDescriptor typeDescriptor = EntityTypeContainer.GetDescriptor(type);

            DbTable dbTable = typeDescriptor.Table;
            if (explicitTableName != null)
                dbTable = new DbTable(explicitTableName, dbTable.Schema);
            string alias = queryModel.GenerateUniqueTableAlias(dbTable.Name);

            queryModel.FromTable = CreateRootTable(dbTable, alias, lockType);

            DbTable aliasTable = new DbTable(alias);
            ComplexObjectModel model = typeDescriptor.GenObjectModel(aliasTable);
            model.DependentTable = queryModel.FromTable;

            queryModel.ResultModel = model;

            return queryModel;
        }