简体   繁体   English

当我尝试获取值时实体框架挂起

[英]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 cleaned my solution清理了我的解决方案

  • 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=&quot;data source=DESKTOP-REKGVD4\SQLEXPRESS;initial catalog=LearningEnglish;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework&quot;" 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.

相关问题 我尝试添加实体时实体框架中的InnerException - InnerException in Entity Framework when I try add an entity 当我尝试通过Entity Framework中的路径/文件名打开MDF数据库时,为什么会出现此错误? - Why do I get this error when I try to open an MDF database via path/filename in Entity Framework? 当我尝试映射实体(实体框架)的属性时,出现错误,类型“ __”必须是非空值类型 - When I try to map the properties for an entity (Entity Framework), I get the error the type '__' must be a non-nullable value type 使用异步调用时实体框架挂起 - Entity Framework hangs when using async calls 当我尝试更新父实体时,实体框架正在更新子实体 - Entity Framework is updating child entity when I try to update parent entity 实体框架:当我按确切日期时间过滤时,出现错误 - Entity Framework : when I filter by exact datetime, I get an error 错误 - 当我尝试在 .net core 2.2 中启用迁移时,项目上未安装实体框架包 - Error -The Entity Framework package is not installed on project when I try to enable migration in .net core 2.2 当我尝试使用带有AutoMapper的Entity Framework Core更新图时出现异常 - Exception when I try to update graph using Entity Framework Core with AutoMapper 试试SaveChanges Entity FrameWork 5 - Try on SaveChanges Entity FrameWork 5 实体框架在加载的DynamicProxies上挂起 - Entity Framework hangs on DynamicProxies loaded
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM