I'm still new to Linq, so if you see something that I really shouldn't do, feel free to suggest changes.
I am working on a new system that allows officers to sign up for overtime work. Part of the data is displayed on a map with search criteria that filter unwanted positions. To simplify the work with data, it is read into the structure of hierarchy objects using Linq. In this example, a job can contain several shifts, and each shift can have several positions. The Linq statement to read them is as follows.
var jobs = (from j in db.Job
join s in db.Shift on j.Id equals s.JobId into shifts
select new JobSearchResult
{
JobNumber = j.Id,
Name = j.JobName,
Latitude = j.LocationLatitude,
Longitude = j.LocationLongitude,
Address = j.AddressLine1,
Shifts = (from shift in shifts
join p in db.Position on shift.Id equals p.ShiftId into positions
select new ShiftSearchResult
{
Id = shift.Id,
Title = shift.ShiftTitle,
StartTime = shift.StartTime,
EndTime = shift.EndTime,
Positions = (from position in positions
select new PositionSearchResult
{
Id = position.Id,
Status = position.Status
}).ToList()
}).ToList()
});
. , , . . . , , , . , .
jobs = jobs.Where(j => j.JobNumber == 1234);
, Shifts Positions. , , ? - , , () .
jobs = jobs.Shifts.Where(s = s.StartTime > JobSearch.StartTime)
- ?