Example #1
0
        /// <summary>
        /// Selects all.
        /// </summary>
        /// <returns></returns>
        /// <exception cref="DatabaseException"></exception>
        public virtual List <T> SelectAll()
        {
            var funcName = "SelectAll";

            Logger.DebugFormat("{0}...", funcName);
            List <T> result;

            try
            {
                var queryArgs = new EntityQueryArgs <T>
                {
                    StartRecordIndex  = 0,
                    NumRecordsPerPage = AppConstants.MaxRecordsPerPage,
                    OrderByExpr       = this.BuildOrderByExpression()
                };
                result = this.GetRecords(queryArgs);
            }
            catch (Exception ex)
            {
                Logger.ErrorFormat("{0} - Exception: {1}", funcName, ex.ToString());
                throw new DatabaseException((int)DatabaseErrorCode.Load, ex);
            }

            Logger.DebugFormat("{0}...DONE", funcName);
            return(result);
        }
Example #2
0
            protected override void OnQuerying(EntityQueryArgs args)
            {
                var query = args.Query;

                query.OrderBy.Add(query.MainTable.Column(AuditItem.LogTimeProperty), OrderDirection.Descending);

                base.OnQuerying(args);
            }
Example #3
0
        protected override void OnQuerying(EntityQueryArgs args)
        {
            var query = args.Query;

            query.OrderBy.Add(query.MainTable.Column(DevLanguageItem.ContentProperty));

            base.OnQuerying(args);
        }
Example #4
0
        protected override void OnQuerying(EntityQueryArgs args)
        {
            var query = args.Query;

            query.OrderBy.Add(query.MainTable.Column(MappingInfo.DevLanguageRDProperty));

            base.OnQuerying(args);
        }
Example #5
0
            protected override void OnQuerying(EntityQueryArgs args)
            {
                var query = args.Query;

                query.OrderBy.Add(query.MainTable.Column(Tag.OrderNoProperty));
                query.OrderBy.Add(query.MainTable.Column(Tag.IdProperty));

                base.OnQuerying(args);
            }
Example #6
0
        protected override void OnQuerying(EntityQueryArgs args)
        {
            var f = QueryFactory.Instance;
            var q = args.Query;

            q.Where = f.And(q.MainTable.Column(BookLoc.LengthProperty).GreaterEqual(0), q.Where);

            base.OnQuerying(args);
        }
Example #7
0
            protected override void OnQuerying(EntityQueryArgs args)
            {
                var q = args.Query;

                q.OrderBy.Add(
                    qf.OrderBy(q.MainTable.Column(DbMigrationHistory.TimeIdProperty), OrderDirection.Descending)
                    );

                base.OnQuerying(args);
            }
Example #8
0
        /// <summary>
        /// 子类重写此方法,查询从持久层加载列表的具体实现。
        /// </summary>
        /// <param name="args">The arguments.</param>
        /// <param name="entityList">The entity list.</param>
        /// <exception cref="System.NotSupportedException">使用内存过滤器的同时,不支持提供分页参数。</exception>
        protected override void QueryListCore(EntityQueryArgs args, EntityList entityList)
        {
            var dp = RdbDataProvider.Get(this.Repo);

            using (var dba = dp.CreateDbAccesser())
            {
                //以下代码,开始访问数据库查询数据。
                var dbTable = dp.DbTable;
                if (args.Filter != null)
                {
                    #region 内存过滤式加载

                    if (!PagingInfo.IsNullOrEmpty(args.PagingInfo))
                    {
                        throw new NotSupportedException("使用内存过滤器的同时,不支持提供分页参数。");
                    }

                    args.MemoryList = new List <Entity>();
                    dbTable.QueryList(dba, args);
                    this.LoadByFilter(args);

                    #endregion
                }
                else
                {
                    if (args.FetchType == FetchType.Count)
                    {
                        #region 查询 Count

                        var count = dbTable.Count(dba, args.Query);
                        entityList.SetTotalCount(count);

                        #endregion
                    }
                    else
                    {
                        //是否需要为 PagingInfo 设置统计值。
                        var pi = args.PagingInfo;
                        var pagingInfoCount = !PagingInfo.IsNullOrEmpty(pi) && pi.IsNeedCount;

                        //如果 pagingInfoCount 为真,则在访问数据库时,会设置好 PagingInfo 的总行数。
                        dbTable.QueryList(dba, args);

                        //最后,还需要设置列表的 TotalCount。
                        if (pagingInfoCount)
                        {
                            entityList.SetTotalCount(pi.TotalCount);
                        }
                    }
                }
            }
        }
Example #9
0
        private EntityList DA_GetWithTasks(int userId)
        {
            var q = this.CreateLinqQuery();

            q = q.Where(e => e.Id == userId);
            var args = new EntityQueryArgs
            {
                Query = this.ConvertToQuery(q),
            };

            args.EagerLoad(TestUser.TestTreeTaskListProperty);
            return(this.QueryList(args));
        }
Example #10
0
        public virtual BookList GetWithEager2()
        {
            var args = new EntityQueryArgs
            {
                Query = QueryFactory.Instance.Query(this)
            };

            args.EagerLoad(Book.ChapterListProperty);
            args.EagerLoad(Chapter.SectionListProperty);
            args.EagerLoad(Section.SectionOwnerProperty);

            return((BookList)this.QueryData(args));
        }
Example #11
0
        private EntityList DA_GetWithEager2()
        {
            var args = new EntityQueryArgs
            {
                Query = QueryFactory.Instance.Query(this)
            };

            args.EagerLoad(Book.ChapterListProperty);
            args.EagerLoad(Chapter.SectionListProperty);
            args.EagerLoad(Section.SectionOwnerProperty);

            return(this.QueryList(args));
        }
Example #12
0
        public virtual TestUser GetWithTasks(int userId)
        {
            var q = this.CreateLinqQuery();

            q = q.Where(e => e.Id == userId);
            var args = new EntityQueryArgs
            {
                Query = this.ConvertToQuery(q),
            };

            args.EagerLoad(TestUser.TestTreeTaskListProperty);
            return((TestUser)this.QueryData(args));
        }
Example #13
0
        /// <summary>
        /// Selects all.
        /// </summary>
        /// <param name="queryArgs">The query parameter.</param>
        /// <returns></returns>
        /// <exception cref="DatabaseException"></exception>
        public virtual List <T> Select(EntityQueryArgs <T> queryArgs)
        {
            var funcName = "Select";

            Logger.DebugFormat("{0}...", funcName);
            List <T> result;

            try
            {
                result = this.GetRecords(queryArgs);
            }
            catch (Exception ex)
            {
                Logger.ErrorFormat("{0} - Exception: {1}", funcName, ex.ToString());
                throw new DatabaseException((int)DatabaseErrorCode.Load, ex);
            }

            Logger.DebugFormat("{0}...DONE", funcName);
            return(result);
        }
Example #14
0
        /// <summary>
        /// Gets the records.
        /// </summary>
        /// <param name="queryArgs">The parameters.</param>
        /// <returns></returns>
        protected virtual List <T> GetRecords(EntityQueryArgs <T> queryArgs)
        {
            lock (syncLock)
            {
                var funcName = "GetRecords";
                Logger.DebugFormat("{0}...", funcName);
                Logger.DebugFormat("{0} - Input parameters: {1}", funcName, queryArgs.ToString());
                List <T> result;

                // Trace SQL generated by the entity framework
                this.dbContext.Database.Log = s => Logger.Debug(Environment.NewLine + "\t" + s);

                // Build query to select records (maybe by foreign key)
                var records = (queryArgs.FilterExpr != null ? dbSet.Where(queryArgs.FilterExpr) : dbSet);

                // Execute query to count total records (maybe by foreign key) from database
                this.TotalRecords = records.Count();

                // User already sort
                if (queryArgs.OrderByExpr != null)
                {
                    // Append order by expression into built query
                    records = queryArgs.SortDirection.Equals("asc")
                        ? records.OrderBy(queryArgs.OrderByExpr)
                        : records.OrderByDescending(queryArgs.OrderByExpr);
                }

                // Append includes queryable to join reference tables into built query
                records = queryArgs.IncludeQueryableFunc == null
                    ? this.BuildIncludesQueryable(records)
                    : queryArgs.IncludeQueryableFunc.Invoke(records);

                // Execute built query to select records from database
                result = records.Skip(queryArgs.StartRecordIndex).Take(queryArgs.NumRecordsPerPage).ToList();

                Logger.DebugFormat("{0}...DONE", funcName);
                return(result);
            }
        }
Example #15
0
        /// <summary>
        /// 子类重写此方法,查询从持久层加载列表的具体实现。
        /// </summary>
        /// <param name="args">The arguments.</param>
        /// <param name="entityList">The entity list.</param>
        /// <exception cref="System.NotSupportedException">使用内存过滤器的同时,不支持提供分页参数。</exception>
        protected override void QueryListCore(EntityQueryArgs args, EntityList entityList)
        {
            var dp = RdbDataProvider.Get(this.Repo);
            using (var dba = dp.CreateDbAccesser())
            {
                //以下代码,开始访问数据库查询数据。
                var dbTable = dp.DbTable;
                if (args.Filter != null)
                {
                    #region 内存过滤式加载

                    if (!PagingInfo.IsNullOrEmpty(args.PagingInfo)) { throw new NotSupportedException("使用内存过滤器的同时,不支持提供分页参数。"); }

                    args.MemoryList = new List<Entity>();
                    dbTable.QueryList(dba, args);
                    this.LoadByFilter(args);

                    #endregion
                }
                else
                {
                    if (args.FetchType == FetchType.Count)
                    {
                        #region 查询 Count

                        var count = dbTable.Count(dba, args.Query);
                        entityList.SetTotalCount(count);

                        #endregion
                    }
                    else
                    {
                        //是否需要为 PagingInfo 设置统计值。
                        var pi = args.PagingInfo;
                        var pagingInfoCount = !PagingInfo.IsNullOrEmpty(pi) && pi.IsNeedCount;

                        //如果 pagingInfoCount 为真,则在访问数据库时,会设置好 PagingInfo 的总行数。
                        dbTable.QueryList(dba, args);

                        //最后,还需要设置列表的 TotalCount。
                        if (pagingInfoCount) { entityList.SetTotalCount(pi.TotalCount); }
                    }
                }
            }
        }