System.StackOverflowException from a simple EF6 qu

2019-07-26 15:03发布

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?

0条回答
登录 后发表回答