|I have the following query.
There is a one-to-many relationship between Jobs->JobSequenceSheets.
I'm joining to JobSequenceSheets. But what I really want is just the COUNT of the JobSequenceSheets records for each Job record.
I'm not sure how to do this. Can someone help?
var datas = (from j in dc.Jobs
join p in dc.Projects on j.ProjectId equals p.Id
join cty in dc.Cities on p.CityId equals cty.Id
join cl in dc.CompanyLocations on p.LocationId equals cl.Id
let jsdr = dc.JobStartDateRevisions.Where(q => q.JobId == j.Id)
.OrderByDescending(q => q.Revision)
join jss in dc.JobSequenceSheets on j.Id equals jss.JobId
let lots = dc.JobSequenceSheets.Where(q => q.JobId == j.Id).Count()
where (jsdr != null && jsdr.StartDate >= startDate && jsdr.StartDate <= endDate)
JobId = j.Id,
JobNumber = j.JobNumber,
Lots = j.Lots,
StartDate = jsdr.StartDate,
ProjectId = p.Id,
ProjectNumber = p.ProjectNumber,
ProjectName = p.ProjectName,
CityId = cty.Id,
City = cty.City1,
LocationId = cl.Id,
Location = cl.Location,
}).OrderBy(x => x.Location)
.ThenBy(x => x.ProjectName)
.ThenBy(x => x.StartDate).ToList();
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
General News Suggestion Question Bug Answer Joke Praise Rant Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.