2014-05-02 58 views
0

我在我的ASP.NET MVC網站上使用EF,並且我注意到一個新的actionresult()方法中存在「問題」。實體框架沒有更新方法中的記錄

在同一個操作中,我在同一個Test表中有兩個操作。

代碼:

//Break point 01 
_documentRepository.UpdateStatus(documentToUpload.IDDocument, Status.Admin); 

//Break point 02 - Just create this aux var to break here and check the database. 
var aux = 1; 

    //Break point 03 
var documents = documentRepository.GetByID(documentToUpload.IDProtocol).ToList(); 
foreach(var doc in documents) 
{ 
    if(doc.Status == Status.Admin) 
    { 
     //Break point 04 
     //Never Breaks here. 
    } 
} 

斷點02火災我去到數據庫,並檢查文件的狀態,並且它已經等於Status.Admin(爲我改變在中斷點01代碼中)。但是,當我得到一份文件清單時,我檢查這份清單,並且文件仍舊保持舊的狀態。

它可能是什麼?

編輯:

庫代碼:

public IEnumerable<Document> GetByID(Guid idProtocol) 
    { 
     return _context.Document.Where(d => d.IDProtocol.Equals(idProtocol)); 
    } 
+0

您確定您更新的文檔位於'documentRepository.GetByID()'返回的列表中嗎? –

+0

可能需要顯示一些存儲庫代碼,以便人們可以看到你如何處理你的EF上下文。 –

+0

@ledbutter是的,我是,因爲我擴大名單並檢查文件的ID。 – gog

回答

0

從來就找到了解決辦法,這是我的錯誤,我做了。我正在使用同一個存儲庫對象來執行這兩個操作。我在Action方法內部創建了一個新的DocumentRepository對象,並使用它來獲取文檔列表,然後我得到了列表更新。

相關問題