Exemplo n.º 1
0
        /// <summary>
        /// 对实体集合进行批量操作。
        /// </summary>
        /// <param name="instances">要操作的实体序列。</param>
        /// <param name="fnOperation">实体操作表达式,权提供 Insert、Update 和 Delete 操作。</param>
        /// <returns>影响的实体数。</returns>
        public int Batch(IEnumerable <TEntity> instances, Expression <Func <IRepository <TEntity>, TEntity, int> > fnOperation)
        {
            var operateName = OperateFinder.Find(fnOperation);
            var eventType   = GetBeforeEventType(operateName);

            return(EntityPersistentSubscribePublisher.OnBatch(instances.Cast <IEntity>(), eventType, () => repositoryProxy.Batch(instances, fnOperation)));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 对实体集合进行批量操作。
        /// </summary>
        /// <param name="instances">要操作的实体序列。</param>
        /// <param name="fnOperation">实体操作表达式,权提供 Insert、Update 和 Delete 操作。</param>
        /// <returns>影响的实体数。</returns>
        public int Batch(IEnumerable <TEntity> instances, Expression <Func <IRepository <TEntity>, TEntity, int> > fnOperation)
        {
            if (instances.IsNullOrEmpty())
            {
                return(-1);
            }

            var operateName = OperateFinder.Find(fnOperation);
            var eventType   = GetBeforeEventType(operateName);

            int func() => repositoryProxy.Batch(instances, fnOperation);

            return(context.Options.NotifyEvents ?
                   EntityPersistentSubscribePublisher.OnBatch(instances.Cast <IEntity>(), eventType, func) :
                   func());
        }