示例#1
0
        /// <summary>
        /// Deletes preset entity
        /// </summary>
        /// <param name="entityToDelete">
        /// Entity to delete
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Throws when passed <paramref name="entityToDelete"/> is null
        /// </exception>
        /// <exception cref="NullReferenceException">
        /// Throws when context for this repository is not set<para/>
        /// Try to call <see cref="SetDbContext(Microsoft.EntityFrameworkCore.Internal.IDbContextDependencies)"/> method
        /// </exception>
        public virtual void Delete(TEntity entityToDelete)
        {
            ContextCheck();
            if (entityToDelete == null)
            {
                throw new ArgumentNullException(nameof(entityToDelete));
            }

            if (dbContext.Entry(entityToDelete).State == EntityState.Detached)
            {
                dbSet.Attach(entityToDelete);
            }
            dbSet.Remove(entityToDelete);
        }
 public void Update(TEntity entityToUpdate)
 {
     dbSet.Attach(entityToUpdate);
     context.Entry(entityToUpdate).State = EntityState.Modified;
 }