Entity FrameWork6 Load takes forever

Benjoe 431 Reputation points
2022-03-22T20:34:18.167+00:00

I have a query which calls Load() after and it takes forever. Is there anyway I can optimize it. Below is my query
var EmpUsers = data.DeptRoles
.Include(x => x.ROLE)
.Include(x => x.USER)
.Where(x => x.Id == deptId && x.USER.Inactive == false);

  EmpUsers.Load(); -----> this takes forever
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,648 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,417 questions
{count} votes

2 answers

Sort by: Most helpful
  1. AgaveJoe 27,696 Reputation points
    2022-03-23T10:52:12.58+00:00

    How long is "takes forever"? How many records are returned? Can you provide the table schema and/or entity design? Maybe you need to add an index on the DeptRoles table?

    0 comments No comments

  2. Benjoe 431 Reputation points
    2022-03-23T12:24:41.687+00:00

    I have fixed the issue myself.

    var EmpUsers = data.DeptRoles;
    var roles = EmpUsers .Include(x => x.ROLE);
    var newUsers = roles.Include(x => x.USER)
    .Where(x => x.Id == deptId && x.USER.Inactive == false);
    newUsers.Load();

    0 comments No comments