System.StackOverflowException from a simple EF6 query

只愿长相守 提交于 2019-12-24 07:32:08

问题


I created a project that references a class library data layer project. The data layer is generated in Visual Studio using Code First from database:

Add New Item => ADO.NET Entity Data Model => Code First from database

I have selected all tables from a huge database (~1000 tables) and at the moment when I try to get something from any of the tables, it just hangs and eventually throws System.StackOverflowException.

The query looks like that:

using (var context = new MyDbModel()) 
{
    var test = context.Student.FirstOrDefault(x => x.studentCode == "ONETWO"); 
    // code is unique, it starts hanging here
}

Running this statement in SSMS takes less than a second. SELECT TOP 1 * FROM Student WHERE studentCode = "ONETWO"

I suppose this causes loading the whole database and therefore the exception, but how can I avoid that?

来源:https://stackoverflow.com/questions/39014320/system-stackoverflowexception-from-a-simple-ef6-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!