使用EntityFramework批次刪除資料

使用EntityFramework批次刪除資料

  1. using (EntitiesContext db = new EntitiesContext(connString))
  2. {
  3. // Retrieve all records from database for deletion
  4. IEnumerable<entity> entityList = db.entity.where(x => x.id == id).toList();
  5. // Use Remove Range function to delete all records at once
  6. db.entity.RemoveRange(entityList);
  7. // Save changes
  8. db.SaveChanges();
  9. }

 

留言

這個網誌中的熱門文章

ORA-12514: TNS: 監聽器目前不知道連線描述區中要求的服務

Oracle 工作排程 DBMS_JOB 筆記

Oracle 例外控制(Exception Control)