コード例 #1
0
 /// <summary>
 /// Deletes the specified entity from the context. It will be deleted
 /// from the database when SaveAllChanges() is called.
 /// If the entity implements <see cref="ISoftDeleteable"/> it will simply
 /// update the <see cref="ISoftDeleteable.IsDeleted"/> property and not
 /// physically remove the instance from the underlying data source.
 /// </summary>
 /// <typeparam name="TEntity">The type of the entity.</typeparam>
 /// <param name="entity">The entity.</param>
 public void Delete <TEntity>(TEntity entity) where TEntity : class
 {
     if (typeof(ISoftDeleteable).IsAssignableFrom(typeof(TEntity)))
     {
         ((ISoftDeleteable)entity).IsDeleted = true;
         context.Entry(entity).State         = EntityState.Modified;
     }
     else
     {
         context.Remove(entity);
     }
 }