예제 #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);

            instances.ForEach(s => EntityPersistentSubscribePublisher.RaiseEvent(s, eventType));

            return(repositoryProxy.Batch(instances, fnOperation));
        }
예제 #2
0
        /// <summary>
        /// 使用一个累加器更新满足条件的一序列对象。
        /// </summary>
        /// <param name="calculator">一个计算器表达式。</param>
        /// <param name="predicate">用于测试每个元素是否满足条件的函数。</param>
        /// <returns>影响的实体数。</returns>
        public int Update(Expression <Func <TEntity, TEntity> > calculator, Expression <Func <TEntity, bool> > predicate)
        {
            var ret = repositoryProxy.Update(calculator, predicate);

            if (ret > 0)
            {
                EntityPersistentSubscribePublisher.RaiseEvent <TEntity>(EntityPersistentEventType.AfterUpdate);
            }

            return(ret);
        }
예제 #3
0
        /// <summary>
        /// 将满足条件的一组对象从库中移除。
        /// </summary>
        /// <param name="predicate">用于测试每个元素是否满足条件的函数。</param>
        /// <param name="logicalDelete">是否为逻辑删除</param>
        /// <returns>影响的实体数。</returns>
        public int Delete(Expression <Func <TEntity, bool> > predicate, bool logicalDelete = true)
        {
            var ret = repositoryProxy.Delete(predicate, logicalDelete);

            if (ret > 0)
            {
                EntityPersistentSubscribePublisher.RaiseEvent <TEntity>(EntityPersistentEventType.AfterRemove);
            }

            return(ret);
        }
예제 #4
0
        /// <summary>
        /// 根据主键值将对象从库中移除。
        /// </summary>
        /// <param name="primaryValues">一组主键值。</param>
        /// <param name="logicalDelete">是否为逻辑删除。</param>
        /// <returns>影响的实体数。</returns>
        public int Delete(object[] primaryValues, bool logicalDelete = true)
        {
            var ret = repositoryProxy.Delete(primaryValues, logicalDelete);

            if (ret > 0)
            {
                EntityPersistentSubscribePublisher.RaiseEvent <TEntity>(EntityPersistentEventType.AfterRemove);
            }

            return(ret);
        }
예제 #5
0
        /// <summary>
        /// 根据主键值将对象从库中移除。
        /// </summary>
        /// <param name="primaryValues">一组主键值。</param>
        /// <returns>影响的实体数。</returns>
        public int Delete(params PropertyValue[] primaryValues)
        {
            var ret = repositoryProxy.Delete(primaryValues, true);

            if (ret > 0)
            {
                EntityPersistentSubscribePublisher.RaiseEvent <TEntity>(EntityPersistentEventType.AfterRemove);
            }

            return(ret);
        }
예제 #6
0
        /// <summary>
        /// 使用一个参照的实体对象更新满足条件的一序列对象。
        /// </summary>
        /// <param name="entity">更新的参考对象。</param>
        /// <param name="predicate">用于测试每个元素是否满足条件的函数。</param>
        /// <returns>影响的实体数。</returns>
        public int Update(TEntity entity, Expression <Func <TEntity, bool> > predicate)
        {
            var ret = repositoryProxy.Update(entity, predicate);

            if (ret > 0 && context.Options.NotifyEvents)
            {
                EntityPersistentSubscribePublisher.RaiseEvent <TEntity>(EntityPersistentEventType.AfterUpdate);
            }

            return(ret);
        }
예제 #7
0
        /// <summary>
        /// 根据主键值将对象从库中移除。
        /// </summary>
        /// <param name="primaryValues">一组主键值。</param>
        /// <param name="logicalDelete">是否为逻辑删除。</param>
        /// <returns>影响的实体数。</returns>
        public int Delete(PropertyValue[] primaryValues, bool logicalDelete = true)
        {
            var ret = repositoryProxy.Delete(primaryValues, logicalDelete);

            if (ret > 0 && context.Options.NotifyEvents)
            {
                EntityPersistentSubscribePublisher.RaiseEvent <TEntity>(EntityPersistentEventType.AfterRemove);
            }

            return(ret);
        }