SQL-184: Retrieve Employee¶
This covers two Employee reads called from SubpoenaService: GetInboxItems retrieves a single Employee by Id inside a foreach loop (an N+1 pattern, one query per inbox item), and InitiateEmployeeList retrieves a projected list of employees whose Id is in a captured id list, ordered by LastName. The Employee entity's ClassMap lives in the external SAIF.Framework.Data.NHibernate package; the backing table resolves to ADP_EMPLOYEE, but its column mappings are unresolved beyond the RPT_MGR_EMPLID self-reference.
Classification¶
| Field | Value |
|---|---|
| SQL ID | SQL-184 |
| Operation type | Read |
| Execution method | ORM (NHibernate LINQ) |
| Database | Oracle |
| Schema | [unqualified]** |
| Command type | N/A (ORM-generated) |
| Business object | SubpoenaService |
| Criteria property | N/A — ORM |
| Lifecycle method | GetInboxItems, InitiateEmployeeList |
Parameters¶
| Parameter | Direction | Type | Max length | Description |
|---|---|---|---|---|
:requestedById |
Input | String | N/A | inboxItem.RequestedById — filters Employee.Id (unresolved mapping) |
:ids |
Input | String[] | N/A | Captured string[] expanded to an IN list (ids.Contains(x.Id)) — filters Employee.Id (unresolved mapping) |
Tables¶
| Table | Access | Columns used |
|---|---|---|
| ADP_EMPLOYEE** | SELECT | Id, UserId, LastName, FirstName, PreferredName (+ full entity in statement 1) — C# property names, column mapping unresolved |
LINQ statement¶
Source: Services/SAIF.Services/Legal/Subpoenas/SubpoenaService.cs:122, with a second fragment at line 321.
// Services/SAIF.Services/Legal/Subpoenas/SubpoenaService.cs:122
var firstOrDefault = _unitOfWork.GetRepository<Employee>()
.Query()
.FirstOrDefault(x => x.Id == inboxItem.RequestedById);
// Services/SAIF.Services/Legal/Subpoenas/SubpoenaService.cs:321
return _unitOfWork.GetRepository<Employee>().Query()
.Where(x => ids.Contains(x.Id))
.OrderBy(x => x.LastName)
.Select(
x =>
new LegalEmployee
{
Id = x.Id,
UserId = x.UserId,
Name =
x.LastName + ", " +
(x.PreferredName.IsNullOrWhiteSpace() ? x.FirstName : x.PreferredName),
IsSelectedUser = (_currentUser == x.UserId ? true : false)
}).ToList();
Sample SQL¶
Inferred SQL: This SQL was inferred from the LINQ statement above and the NHibernate mappings. It is not concrete SQL from source code; NHibernate generates the executed statement at runtime, so aliases, column order, join syntax, and bind-parameter names may differ.
-- Inferred from LINQ (NHibernate mapping translation); not concrete SQL
-- (1) L122 — GetInboxItems (once per inbox item in the foreach at L119)
SELECT * FROM (
SELECT E.Id, E.UserId, E.EmployeeStatusCode, E.FirstName, E.LastName, E.PreferredName,
E.EmailAddress, E.Phone, E.Department, E.JobTitle /* , ...remaining EmployeeMap columns */
-- unresolved mapping: Employee.* (C# property names; physical columns not resolvable)
FROM ADP_EMPLOYEE E
WHERE E.Id = :requestedById -- unresolved mapping: Employee.Id
) WHERE ROWNUM <= 1;
-- (2) L321 — InitiateEmployeeList (projection; see notes)
SELECT E.Id, E.UserId, E.LastName, E.PreferredName, E.FirstName -- unresolved mapping: Employee.*
FROM ADP_EMPLOYEE E
WHERE E.Id IN (:ids) -- unresolved mapping: Employee.Id
ORDER BY E.LastName;
Translation notes:
- ** = unresolved column mapping (C# property names shown). Table name ADP_EMPLOYEE is resolved from Legends documentation of SAIF.Framework.Data.NHibernate.
- FirstOrDefault uses the Oracle10 dialect wrapper SELECT * FROM (...) WHERE ROWNUM <= 1.
- Statement (1) is an N+1 pattern — one query per inbox item.
- Statement (2)'s projection uses the IsNullOrWhiteSpace() extension, which is evaluated client-side; the SQL selects only the referenced columns.
- CL_CLAIM_EMP_BUS_FUNC_LIMIT is not accessed here: the L313 limits query that produces ids is a separate, already-materialized statement (SQL-187); ids is an in-memory array by the time this statement runs.
Operations and processes¶
- SubpoenaService.GetInboxItems — see Operations and processes
- SubpoenaService.InitiateEmployeeList — see Operations and processes
Sources¶
Services/SAIF.Services/Legal/Subpoenas/SubpoenaService.cs (L122, L321)