private void Prefetch() { using (CssDiscoveryEntities db = new CssDiscoveryEntities()) { _projectPackages = db.ProjectPackageRelationship .Include("Package") .ToList(); _packagesWithoutProjects = ( from package in db.Package join rel in db.ProjectPackageRelationship on package.Id equals rel.PackageID into j from outerRel in j.DefaultIfEmpty() where outerRel == null select package ).Where(p => !p.DefaultPackage).ToList(); _packageFundraisingNeedsByPackage = db.Package .ToDictionary( r => r.Id, r => r.PackageFundraisingNeeds .Select(n => new FundraisingNeedDto() { FiscalYear = n.FiscalYear, DollarAmount = n.DollarAmount }).ToList()); _defaultPackage = db.Package.Where(r => r.DefaultPackage).FirstOrDefault(); } _packageFundraisingNeedsByProject = new Dictionary<int, List<FundraisingNeedDto>>(); using (CIHEntities db = new CIHEntities()) { foreach (var packageGroup in _projectPackages.GroupBy(r => r.PackageID)) { _packageFundraisingNeedsByProject[packageGroup.First().PackageID] = packageGroup .Join(db.CihProject, g => g.ProjectID, p => p.Id, (r, p) => new { PackageId = r.PackageID, Project = p }) .Select(r => r.Project.FundraisingNeeds) .SelectMany(r => r) .Select(r => new FundraisingNeedDto() { FiscalYear = r.FiscalYear, DollarAmount = r.DollarAmount }).ToList(); } } }
private void PrefetchData() { if (!_dataFetched) { using (CssDiscoveryEntities db = new CssDiscoveryEntities()) { IQueryable<ProjectKeywordRelation> rs = db.ProjectKeywordRelation.Select(r => r); foreach (ProjectKeywordRelation r in rs) { ProjectKeywordDto word = new ProjectKeywordDto() { ProjectId = r.ProjectId, Keyword = r.Keyword.Word }; ProjectsKeywords.Add(word); } } _dataFetched = true; } }