重构代码以删除记录

时间:2014-03-31 16:19:16

标签: c# asp.net-mvc asp.net-mvc-3

 if (StockLocationRecordsToBeDeleted != null)
 {
     foreach (int _serverId in StockLocationRecordsToBeDeleted)
     {
         StockLocation_Record RecordToRemove = db.StockLocation_Record.Where(x => x.ServerLocationId == _serverId).FirstOrDefault();

         if (RecordToRemove != null)
         {
             db.StockLocation_Record.DeleteObject(RecordToRemove);
             db.SaveChanges();
         }
     }
}

这已成功删除了一条记录,但是我必须先创建一个新的StockLocation_Record,而不能DeleteObject(RecordToRemove).Where(ServerId == _serverId)

0 个答案:

没有答案