[英]Entity Framework hangs when I try to get values
My program hangs when it gets values using Entity Framework.我的程序在使用实体框架获取值时挂起。 Here is my simple code:
这是我的简单代码:
LearningEnglishEntities db2 = new LearningEnglishEntities();
List<tb_Words> searchedItems = db2.tb_Words.ToList(); // it hangs here
It's not an async method.这不是异步方法。 There are solutions about
async
but I didn't find any solution to fix my problem.有关于
async
解决方案,但我没有找到任何解决方案来解决我的问题。
It doesn't respond, it's waiting forever.它没有响应,它一直在等待。 All my code was running until 2 days ago.
我所有的代码一直运行到 2 天前。 I didn't type or do anything and this bug happened (short video is here )
我没有打字或做任何事情,这个错误发生了(短视频在这里)
I have tried these things so far:到目前为止,我已经尝试过这些事情:
I removed Entity Framework model from my solution and I added it again我从解决方案中删除了实体框架模型,然后再次添加了它
I created a new program and I used exactly same codes and model (it worked):我创建了一个新程序,并使用了完全相同的代码和模型(它有效):
LearningEnglishEntities1 db = new LearningEnglishEntities1(); List<tb_Words> sample = db.tb_Words.ToList(); // It worked
I typed this code:我输入了这个代码:
var query = from item in db.tb_Words select item; // It hangs the same way
I checked this code is not run by another thread:我检查了这段代码不是由另一个线程运行的:
bool query0 = this.InvokeRequired; if (!query0) { LearningEnglishEntities db2 = new LearningEnglishEntities(); List<tb_Words> searchedItems = db2.tb_Words.ToList(); // It still hangs }
I changed my Entity Framework 6.0x version to 5.0x but it didn't work.我将我的 Entity Framework 6.0x 版本更改为 5.0x,但它不起作用。
I completely copied all files and pasted to a new project.我完全复制了所有文件并粘贴到一个新项目中。 It ran but it didn't work
它运行了,但没有用
I restarted Microsoft Distributed Transaction Coordinator Service and checked startup type is Automatically.我重新启动了 Microsoft 分布式事务协调器服务并检查了启动类型是自动。 It didn't work.
它没有用。
Strangely, it works on other projects but it hangs on this project.奇怪的是,它适用于其他项目,但它挂在这个项目上。 I haven't found any solution to fix this bug.
我还没有找到任何解决方案来修复这个错误。 Do you think what should i do?
你觉得我该怎么办?
Also My Connection String is :另外我的连接字符串是:
<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>
Thank you谢谢
After all things, I was able to find a solution but I don't know the reason.毕竟,我能够找到解决方案,但我不知道原因。 Using Entity Framework Code First solved my problem.
使用 Entity Framework Code First 解决了我的问题。 It is not good for my project but i have to use it.
它对我的项目不利,但我必须使用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.