[英]Entity Framework hangs when I try to get values
我的程序在使用實體框架獲取值時掛起。 這是我的簡單代碼:
LearningEnglishEntities db2 = new LearningEnglishEntities();
List<tb_Words> searchedItems = db2.tb_Words.ToList(); // it hangs here
這不是異步方法。 有關於async
解決方案,但我沒有找到任何解決方案來解決我的問題。
它沒有響應,它一直在等待。 我所有的代碼一直運行到 2 天前。 我沒有打字或做任何事情,這個錯誤發生了(短視頻在這里)
到目前為止,我已經嘗試過這些事情:
我從解決方案中刪除了實體框架模型,然后再次添加了它
我創建了一個新程序,並使用了完全相同的代碼和模型(它有效):
LearningEnglishEntities1 db = new LearningEnglishEntities1(); List<tb_Words> sample = db.tb_Words.ToList(); // It worked
我清理了我的解決方案
我輸入了這個代碼:
var query = from item in db.tb_Words select item; // It hangs the same way
我檢查了這段代碼不是由另一個線程運行的:
bool query0 = this.InvokeRequired; if (!query0) { LearningEnglishEntities db2 = new LearningEnglishEntities(); List<tb_Words> searchedItems = db2.tb_Words.ToList(); // It still hangs }
我將我的 Entity Framework 6.0x 版本更改為 5.0x,但它不起作用。
我完全復制了所有文件並粘貼到一個新項目中。 它運行了,但沒有用
我重新啟動了 Microsoft 分布式事務協調器服務並檢查了啟動類型是自動。 它沒有用。
奇怪的是,它適用於其他項目,但它掛在這個項目上。 我還沒有找到任何解決方案來修復這個錯誤。 你覺得我該怎么辦?
另外我的連接字符串是:
<connectionStrings><add name="LearningEnglishEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=DESKTOP-REKGVD4\SQLEXPRESS;initial catalog=LearningEnglish;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient" /></connectionStrings>
謝謝
畢竟,我能夠找到解決方案,但我不知道原因。 使用 Entity Framework Code First 解決了我的問題。 它對我的項目不利,但我必須使用它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.