/// <summary>
        /// Loads the full tree of funds and budgets
        /// </summary>
        public async Task <Fund> Run()
        {
            Fund root = await this.unitOfWork.GetRepository <Fund>()
                        .GetAll()
                        .Include(f => f.Duration)
                        .SingleAsync(b => b.UserId == this.userId &&
                                     b.ParentFund == null);

            DateTime           currentTime = DateTime.Now;
            IQuerySet <Budget> rootBudgets = this.unitOfWork.GetRepository <Budget>()
                                             .GetAll()
                                             .Include(b => b.BudgetPeriod)
                                             .Where(b => b.FundId == root.Id);
            Budget currentRootBudget = await BudgetPeriodQueryUtils.GetForDate(rootBudgets, DateTime.Now);

            currentRootBudget.Fund = root;
            root.HistoricalBudgets = new List <Budget>()
            {
                currentRootBudget
            };

            root = await this.budgetLoader.LoadFundTree(root, currentRootBudget.BudgetPeriod);

            return(root);
        }
예제 #2
0
        public IJoinedResult <TEntity, TJoin1, TJoin2, TJoin3, TJoin4> Join <TJoin4>(IQuerySet <TJoin4> querySet, Expression <Func <TEntity, TJoin1, TJoin2, TJoin3, TJoin4, bool> > onExpression)
        {
            AssertUtil.ArgumentNotNull(querySet, nameof(querySet));

            if (querySet.Session != this.Session)
            {
                throw new ArgumentException($"Argument '{querySet}' isnot in the same session.");
            }

            var queryContext = this.QueryContext.SnapshotForAction(DbQueryAction.SetJoin);

            queryContext.AddJoin(querySet as DbQuerySet <TJoin4>, onExpression);

            return(this.Session.CreateJoinedResult <TEntity, TJoin1, TJoin2, TJoin3, TJoin4>(queryContext));
        }
예제 #3
0
파일: DbQuerySet.cs 프로젝트: weikety/ECode
        public IQuerySet <TEntity> UnionAll(IQuerySet <TEntity> querySet)
        {
            AssertUtil.ArgumentNotNull(querySet, nameof(querySet));

            if (querySet.Session != this.Session)
            {
                throw new ArgumentException($"Argument '{querySet}' isnot in the same session.");
            }

            var queryContext = this.QueryContext.SnapshotForAction(DbQueryAction.SetUnion);

            queryContext.AddUnionAll(querySet as DbQuerySet <TEntity>);

            return(this.Session.CreateQuerySet <TEntity>(queryContext));
        }
예제 #4
0
        public async Task <Fund> Run()
        {
            DateTime                   now        = DateTime.Now.Date;
            IRepository <Fund>         fundRepo   = this.unitOfWork.GetRepository <Fund>();
            IRepository <BudgetPeriod> periodRepo = this.unitOfWork.GetRepository <BudgetPeriod>();
            Fund rootFund = await fundRepo.GetAll()
                            .SingleAsync(f => f.UserId == this.userId &&
                                         !f.ParentFundId.HasValue);

            IQuerySet <BudgetPeriod> usersBudgetPeriods = periodRepo.GetAll().Include(p => p.RootBudget)
                                                          .Where(p => p.RootBudget.FundId == rootFund.Id);
            BudgetPeriod currentPeriod = await BudgetPeriodQueryUtils.GetForDate(usersBudgetPeriods, this.date);

            rootFund = await this.budgetLoader.LoadFundTree(rootFund, currentPeriod);

            return(rootFund);
        }
 /// <summary>
 /// 排除在工作单元外
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="querySet"></param>
 /// <returns></returns>
 public static IQuerySet <T> NotUnitOfWork <T>(this IQuerySet <T> querySet)
 {
     NotUnitOfWork(querySet as QuerySet <T>);
     return(querySet);
 }
 /// <summary>
 /// 获取自定义仓储
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="querySet"></param>
 /// <returns></returns>
 public static IBaseRepository <T> GetRepository <T>(this IQuerySet <T> querySet)
 {
     return((querySet as QuerySet <T>).GetRepository());
 }
예제 #7
0
 public static Task <BudgetPeriod> GetForDate(IQuerySet <BudgetPeriod> source, DateTime date)
 {
     return(source.SingleAsync(p => p.StartDate.Date <= date.Date && p.EndDate.Date >= date.Date));
 }