Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public async Task<IEnumerable<AuditHeader>> GetOpen()
- {
- var lookup = new Dictionary<int, AuditHeader>();
- using (var connection = await Conn.GetOpenConnectionAsync())
- {
- string sql = @"SELECT AH.*, AD.*, Loc.*, Aud.*, Sh.*
- FROM AuditHeader as AH
- Inner Join AuditDtl as AD
- ON AH.ID = AD.AuditHeader_ID
- INNER JOIN Location as loc
- ON AH.Location_ID = Loc.ID
- INNEr JOIN Auditor as Aud
- ON AH.Auditor_ID = Aud.ID
- INNER JOIN Shift as sh
- ON AH.Shift_ID = sh.ID
- WHERE AH.EnteredDate is null ;";
- var headers = await connection.QueryAsync<AuditHeader, AuditDtl, Location, Auditor, Shift, AuditHeader>(
- sql,
- (h, d, l, a, s) =>
- {
- AuditHeader header;
- if (!lookup.TryGetValue(h.ID, out header))
- {
- lookup.Add(h.ID, header = h);
- }
- if (header.AuditDtl == null)
- header.AuditDtl = new List<AuditDtl>();
- header.AuditDtl.Add(d);
- if (header.Loction == null)
- header.Loction = new Location();
- header.Loction = l;
- if (header.Auditor == null)
- header.Auditor = new Auditor();
- header.Auditor = a;
- if (header.Shift == null)
- header.Shift = new Shift();
- header.Shift.ID = s.ID;
- header.Shift.ShiftDescription = s.ShiftDescription;
- return header;
- }
- );
- return headers.Distinct();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement