In building complex calls with the repository pattern for the first time, I’m researching best practices.
The response in this post Having a repository dependent on another repository seems to suggest that we cannot reference other repositories.
Fine. Makes sense.
Any issue with referencing other tables from the Entity Framework context within a repository method? Such as the Users
within the ProjectRepository
in the example method below? Or is there a better pattern:
internal class ProjectRepository : Repository<Project>, IProjectRepository
{
public __GlobalDbContext GlobalDbContext
{
get { return Context as __GlonalDBContext; }
}
public ProjectRepository(__GlonalDBContext context) : base(context) { }
public IEnumerable<Project> GetProjectsWithUsers()
{
List<Guid?> us = GlobalDbContext.Users.Select(u => u.ProjectGuid).ToList();
return GlobalDbContext.Projects.Where(p => us.Contains(p.ProjectGuid));
}
}