Exemple #1
0
        private FromSection <T> Join <TJoin>(Table table, WhereClip onWhere, JoinType joinType)
            where TJoin : Entity
        {
            TJoin entity = DataUtils.CreateInstance <TJoin>();

            this.entityList.Add(entity);

            if ((IField)query.PagingField == null)
            {
                //标识列和主键优先,包含ID的列被抛弃
                query.PagingField = entity.PagingField;
            }

            FromSection <TJoin> from = new FromSection <TJoin>(table);
            string strJoin           = string.Empty;

            if (onWhere != null)
            {
                strJoin = " on " + onWhere.ToString();
            }

            string join = GetJoinEnumString(joinType);

            if (this.relation != null)
            {
                this.tableName = " {2} " + this.tableName;
                this.relation += " {3} ";
            }
            this.relation += join + from.TableName + strJoin;

            return(this);
        }
Exemple #2
0
 internal QuerySection(FromSection <T> fromSection, DbProvider dbProvider, DbTrans dbTran, Field pagingField)
 {
     this.fromSection = fromSection;
     this.dbProvider  = dbProvider;
     this.dbTran      = dbTran;
     this.pagingField = pagingField;
 }
Exemple #3
0
        /// <summary>
        /// 返回一个Query节
        /// </summary>
        /// <returns></returns>
        public QuerySection From(QueryCreator creator)
        {
            if (creator.Table == null)
            {
                throw new DataException("用创建器操作时,表不能为null!");
            }

            FromSection <ViewEntity> f = this.From <ViewEntity>(creator.Table);

            if (creator.IsRelation)
            {
                foreach (TableJoin join in creator.Relations.Values)
                {
                    if (join.Type == JoinType.LeftJoin)
                    {
                        f.LeftJoin <ViewEntity>(join.Table, join.Where);
                    }
                    else if (join.Type == JoinType.RightJoin)
                    {
                        f.RightJoin <ViewEntity>(join.Table, join.Where);
                    }
                    else
                    {
                        f.InnerJoin <ViewEntity>(join.Table, join.Where);
                    }
                }
            }

            QuerySection <ViewEntity> query = f.Select(creator.Fields).Where(creator.Where)
                                              .OrderBy(creator.OrderBy);

            return(new QuerySection(query));
        }
Exemple #4
0
        /// <summary>
        /// 判断记录是否存在
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="table"></param>
        /// <param name="entity"></param>
        /// <returns></returns>
        private bool Exists <T>(Table table, T entity)
            where T : Entity
        {
            WhereClip where = DataUtils.GetPkWhere <T>(table, entity);
            FromSection <T> fs = new FromSection <T>(dbProvider, dbTrans, table);

            return(fs.Where(where).Count() > 0);
        }
Exemple #5
0
        /// <summary>
        /// 判断记录是否存在
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="table"></param>
        /// <param name="where"></param>
        /// <returns></returns>
        private bool Exists <T>(Table table, WhereClip where)
            where T : Entity
        {
            if (where == null || where == WhereClip.None)
            {
                throw new DataException("在判断记录是否存在时出现异常,条件为null或WhereClip.None!");
            }

            FromSection <T> fs = new FromSection <T>(dbProvider, dbTrans, table, null);

            return(fs.Where(where).Count() > 0);
        }
Exemple #6
0
        /// <summary>
        /// 返回一个From节
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public FromSection <T> From <T>(TableRelation <T> relation)
            where T : Entity
        {
            FromSection <T> section = From <T>();

            section.SetQuerySection(relation.Section.Query);

            //给查询设置驱动与事务
            section.Query.SetDbProvider(dbProvider, this);

            return(section);
        }
Exemple #7
0
        internal TableRelation(Table table)
        {
            if (table == null)
            {
                this.section = new FromSection <T>(null, null, Table.GetTable <T>());
            }
            else
            {
                this.section = new FromSection <T>(null, null, table);
            }

            this.section.EntityList.Add(DataUtils.CreateInstance <T>());
        }
Exemple #8
0
 internal QuerySection(FromSection <T> fromSection)
 {
     this.fromSection = fromSection;
 }
Exemple #9
0
 internal TopSection(string topString, FromSection <T> fromSection, DbProvider dbProvider, DbTrans dbTran, Field pagingField, int topSize)
     : base(fromSection, dbProvider, dbTran, pagingField)
 {
     this.topString = topString;
     this.topSize   = topSize;
 }
Exemple #10
0
 internal QuerySection(FromSection <T> fromSection, DbProvider dbProvider, DbTrans dbTran)
 {
     this.fromSection = fromSection;
     this.dbProvider  = dbProvider;
     this.dbTran      = dbTran;
 }