我想從我的表中刪除一個記錄使用EF,並沒有發生任何事情。代碼執行時沒有任何錯誤,但記錄只是在DB中執行。我在其他地方有幾乎相同的代碼。實體框架4刪除調用不工作
using (var DB = new PTNWebConfigurationModel.PTNWebConfigurationEntities())
{
var account = DB.Accounts.Where(a => a.LoginID == loginID).FirstOrDefault();
//Load existing session for the Account, otherwise create a new one.
if (!LoadExistingSession(ip, DB, account))
{
CreateNewSession(ip, DB, account);
}
AccountsSession sessionsToDelete = DB.AccountsSessions.Where(a => a.RemoteIP == ip && a.AccountID == 1).FirstOrDefault();
if (sessionsToDelete != null)
{
DB.DeleteObject(sessionsToDelete);
DB.SaveChanges();
}
}
我也與這些選項試了一下:
DB.DeleteObject(sessionsToDelete);
DB.SaveChanges(System.Data.Objects.SaveOptions.DetectChangesBeforeSave);
DB.AcceptAllChanges();
我也開始不使用塊,公正和實體實例化對象,但也不能工作。
你沒有一個封閉的TransactionScope,你沒有完成,對吧? – 2011-01-07 17:48:15
你可以試試http://efprof.com/ – TrueWill 2011-01-07 17:55:02