Ejemplo n.º 1
0
 public QueryResult <CDistributionManagerPO> GetCDistributionManagerWithTotalCountByPredicate(IPredicate predicate, int startIndex, int count, params ISort[] sorts)
 {
     return(EntityContextFactory.Execute <QueryResult <CDistributionManagerPO> >((entityContext) =>
     {
         return this.GetCDistributionManagerWithTotalCountByPredicateWithContext(entityContext, predicate, startIndex, count, sorts);
     }));
 }
 public Core.Data.QueryResult <CPropertyCategoryPO> GetPropertyCategoryWithTotalCountByPredicate(IPredicate predicate, int startIndex, int count, params ISort[] sorts)
 {
     return(EntityContextFactory.Execute <Core.Data.QueryResult <CPropertyCategoryPO> >((entityContext) =>
     {
         return this.GetPropertyCategoryWithTotalCountByPredicateWithContext(entityContext, predicate, startIndex, count, sorts);
     }));
 }
        /// <summary>
        /// 执行一个不需要返回结果的函数,该函数可接收一个已初始化的 IEntityContext 参数。
        /// 如果在执行过程中发生并发冲突,则会额外进行 concurrencyRetryCount 参数指定次数的重试,默认执行 1 次重试。
        /// </summary>
        /// <typeparam name="TResult">函数执行结果的类型。</typeparam>
        /// <param name="func">要执行的函数。</param>
        /// <param name="concurrencyRetryCount">并发重试次数。</param>
        /// <returns>函数执行的结果。</returns>
        public static TResult Execute <TResult>(Func <IEntityContext, TResult> func, int concurrencyRetryCount = 1)
        {
            int retryCount = 0;

            while (true)
            {
                using (IEntityContext entityContext = EntityContextFactory.CreateEntityContext())
                {
                    try
                    {
                        return(func(entityContext));
                    }
                    catch (EntityConcurrencyException)
                    {
                        retryCount++;

                        if (retryCount > concurrencyRetryCount)
                        {
                            throw;
                        }

                        continue;
                    }
                    catch
                    {
                        throw;
                    }
                }
            }
        }
Ejemplo n.º 4
0
 public CDistributionManagerPO GetById(int id, bool throwExceptionWhenNotExists)
 {
     return(EntityContextFactory.Execute <CDistributionManagerPO>((entityContext) =>
     {
         return this.GetByIdWithContext(entityContext, id, throwExceptionWhenNotExists);
     }));
 }
        /// <summary>
        /// 执行一个不需要返回结果的函数,该函数可接收一个已初始化的 IEntityContext 参数。
        /// 如果在执行过程中发生并发冲突,则会额外进行 concurrencyRetryCount 参数指定次数的重试,默认执行 1 次重试。
        /// </summary>
        /// <param name="action">要执行的函数。</param>
        /// <param name="concurrencyRetryCount">并发重试次数。</param>
        public static void Execute(Action <IEntityContext> action, int concurrencyRetryCount = 1)
        {
            int retryCount = 0;

            while (true)
            {
                using (IEntityContext entityContext = EntityContextFactory.CreateEntityContext())
                {
                    try
                    {
                        action(entityContext);

                        break;
                    }
                    catch (EntityConcurrencyException)
                    {
                        retryCount++;

                        if (retryCount > 3)
                        {
                            throw;
                        }

                        continue;
                    }
                    catch
                    {
                        throw;
                    }
                }
            }
        }
 public QueryResult <CCashCouponDetailPO> GetCCashCouponDetailWithTotalCountByPredicate(IPredicate predicate, int startIndex, int count, params ISort[] sorts)
 {
     return(EntityContextFactory.Execute <QueryResult <CCashCouponDetailPO> >((entityContext) =>
     {
         return this.GetCCashCouponDetailWithTotalCountByPredicateWithContext(entityContext, predicate, startIndex, count, sorts);
     }));
 }
 public CCashCouponDetailPO GetById(int id, bool throwExceptionWhenNotExists)
 {
     return(EntityContextFactory.Execute <CCashCouponDetailPO>((entityContext) =>
     {
         return this.GetByIdWithContext(entityContext, id, throwExceptionWhenNotExists);
     }));
 }
Ejemplo n.º 8
0
 public CResCoordinatePO GetById(int id, bool throwExceptionWhenNotExists)
 {
     return(EntityContextFactory.Execute <CResCoordinatePO>((entityContext) =>
     {
         return this.GetByIdWithContext(entityContext, id, throwExceptionWhenNotExists);
     }));
 }
        /// <summary>
        /// 在事物中执行一个不需要返回结果的函数,该函数可接收一个已初始化的 IEntityContext 参数。
        /// 如果在执行过程中发生并发冲突,则会额外进行 concurrencyRetryCount 参数指定次数的重试,默认执行 1 次重试。
        /// </summary>
        /// <param name="action">要在事物中执行的函数。</param>
        /// <param name="concurrencyRetryCount">并发重试次数。</param>
        public static void ExecuteInTransition(Action <IEntityContext> action, int concurrencyRetryCount = 1)
        {
            int retryCount = 0;

            while (true)
            {
                using (IEntityContext entityContext = EntityContextFactory.CreateEntityContext())
                {
                    try
                    {
                        entityContext.BeginTransaction();

                        action(entityContext);

                        entityContext.Commit();

                        break;
                    }
                    catch (EntityConcurrencyException)
                    {
                        entityContext.Rollback();

                        retryCount++;

                        if (retryCount > concurrencyRetryCount)
                        {
                            throw;
                        }

                        continue;
                    }
                    catch
                    {
                        entityContext.Rollback();

                        throw;
                    }
                }
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 在事物中执行一个需要返回结果的函数,该函数可接收一个已初始化的 IEntityContext 参数。
        /// 如果在执行过程中发生并发冲突,则会额外进行 concurrencyRetryCount 参数指定次数的重试,默认执行 1 次重试。
        /// </summary>
        /// <typeparam name="TResult">函数执行结果的类型。</typeparam>
        /// <param name="func">要在事物中执行的函数。</param>
        /// <param name="concurrencyRetryCount">并发重试次数。</param>
        /// <returns>函数执行的结果。</returns>
        public static TResult ExecuteInTransition <TResult>(Func <IEntityContext, TResult> func, int concurrencyRetryCount = 1)
        {
            int retryCount = 0;

            while (true)
            {
                using (IEntityContext entityContext = EntityContextFactory.CreateEntityContext())
                {
                    try
                    {
                        entityContext.BeginTransaction();

                        var result = func(entityContext);

                        entityContext.Commit();

                        return(result);
                    }
                    catch (EntityConcurrencyException)
                    {
                        entityContext.Rollback();

                        retryCount++;

                        if (retryCount > concurrencyRetryCount)
                        {
                            throw;
                        }

                        continue;
                    }
                    catch
                    {
                        entityContext.Rollback();

                        throw;
                    }
                }
            }
        }
Ejemplo n.º 11
0
 /// <summary>
 /// 创建可同时执行读写或者只读操作的实体访问上下文对象。
 /// </summary>
 /// <returns></returns>
 public IEntityContext CreateEntityContext(bool readOnly)
 {
     return(EntityContextFactory.CreateEntityContext(readOnly));
 }
Ejemplo n.º 12
0
 /// <summary>
 /// 创建可同时执行读写操作的实体访问上下文对象。
 /// </summary>
 /// <returns></returns>
 public IEntityContext CreateEntityContext()
 {
     return(EntityContextFactory.CreateEntityContext());
 }
Ejemplo n.º 13
0
 public QueryResult <CCommodityPropertyPO> GetCommodityPropertyWithTotalCountByPredicate(IPredicate predicate, int startIndex, int count, params ISort[] sorts)
 {
     return(EntityContextFactory.Execute <QueryResult <CCommodityPropertyPO> >(entityContext => this.GetCommodityPropertyWithTotalCountByPredicateWithContext(entityContext, predicate, startIndex, count, sorts), 1));
 }