/// <summary>
        /// 根据实体的状态,插入或更新实体对象。
        /// </summary>
        /// <param name="entity">要保存的实体对象。</param>
        /// <returns>影响的实体数。</returns>
        public int InsertOrUpdate(TEntity entity)
        {
            Guard.ArgumentNull(entity, nameof(entity));

            if (entity.EntityState == EntityState.Attached)
            {
                return(EntityPersistentSubscribePublisher.OnCreate(entity, () => repositoryProxy.Insert(entity)));
            }
            else
            {
                return(EntityPersistentSubscribePublisher.OnUpdate(entity, () => repositoryProxy.Update(entity)));
            }
        }
        /// <summary>
        /// 更新一个实体对象。
        /// </summary>
        /// <param name="entity">实体对象。</param>
        /// <returns>影响的实体数。</returns>
        public int Update(TEntity entity)
        {
            Guard.ArgumentNull(entity, nameof(entity));

            if (context.Options.ValidateEntity)
            {
                ValidationUnity.Validate(entity);
            }

            int func() => repositoryProxy.Update(entity);

            return(context.Options.NotifyEvents ?
                   EntityPersistentSubscribePublisher.OnUpdate(entity, func) : func());
        }
        /// <summary>
        /// 更新一个实体对象。
        /// </summary>
        /// <param name="entity">实体对象。</param>
        /// <returns>影响的实体数。</returns>
        public int Update(TEntity entity)
        {
            Guard.ArgumentNull(entity, nameof(entity));

            return(EntityPersistentSubscribePublisher.OnUpdate(entity, () => repositoryProxy.Update(entity)));
        }