我正在使用實體框架6.當我使用EF更新數據庫的列時。記錄更新沒有任何問題,但在更改SQL Server中使用更新查詢的列的值後,EF不會更新列值,也不會引發任何異常。在更改SQL Server中列的值後,實體框架不更新列
CustomerMandate customerMandate = await DbContext.CustomerMandates.FirstOrDefaultAsync(mandate => mandate.Id == 1, cancellationToken);
if (customerMandate != null)
{
customerMandate.State = newState;
await DbContext.SaveChangesAsync(cancellationToken);// not working
}
DbContext newContext = new DbContext();
CustomerMandate customerMandate1 = await newContext.CustomerMandates.FirstOrDefaultAsync(mandate => mandate.Id == 1, cancellationToken);
if (customerMandate1 != null)
{
customerMandate1.State = newState;
await DbContext.SaveChangesAsync(cancellationToken);// working
}
在正常的應用程序更新的執行
是好的,但是當我使用T-SQL DbContext.ChangeTracker.HasChanges()返回false數據庫中更改值,但是當我創造新的上下文,並從數據庫獲取記錄,並改變它的DbContext .ChangeTracker.HasChanges()返回true 任何想法?
請與我們分享您的密碼。 –
糾正我,如果我錯了,當你使用更新語句使用EF它的工作原理,當你使用TSQL更新語句它不? – Valkyrie
您如何嘗試更新TSQL中的記錄?我的意思是如果你在代碼中的某個地方使用斷點? – MKR