Entity FrameWork6 Load takes forever

Benjoe 431 Reputation points

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
Microsoft Technologies based on the .NET software framework.
3,456 questions
A set of technologies in the .NET Framework for building web applications and XML web services.
3,307 questions
{count} votes

2 answers

Sort by: Most helpful
  1. AgaveJoe 26,166 Reputation points

    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

    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);

    0 comments No comments