---
title: "SQL-159: LegalQueryProvider.GetAdpEmployeeName"
summary: Read operation for `LegalQueryProvider.GetAdpEmployeeName`
status: draft
owner: SAIF.Core documentation team
last_reviewed: 2026-09-24
library: SAIF.Data
reference_type: package
---

# SQL-159: LegalQueryProvider.GetAdpEmployeeName

This statement is a read operation invoked through ORM (NHibernate LINQ). Executed by `LegalQueryProvider.GetAdpEmployeeName`.

## Classification

| Field | Value |
| --- | --- |
| **SQL ID** | SQL-159 |
| **Operation type** | Read |
| **Execution method** | ORM (NHibernate LINQ) |
| **Database** | Unknown** |
| **Schema** | Unknown** |
| **Command type** | N/A (ORM-generated) |
| **Business object** | `LegalQueryProvider` |
| **Criteria property** | N/A — ORM |
| **Lifecycle method** | `GetAdpEmployeeName` |

## Parameters

| Parameter | Direction | Type | Max length | Description |
| --- | --- | --- | --- | --- |
| `emplId` | Input | string | N/A | Method argument of `LegalQueryProvider.GetAdpEmployeeName` bound into the ORM expression; NHibernate generates the bind variable at runtime |

## Tables

| Table | Access | Columns used |
| --- | --- | --- |
| [ADP_EMPLOYEE](../database-tables.md#adp_employee)** | SELECT | EMPLID (Id), RPT_MGR_EMPLID (resolved via Legends); FirstName / LastName / PreferredName columns **unresolved** |

## LINQ statement

Source: `Data/SAIF.Data/Queries/Legal/LegalQueryProvider.cs:94-95`.

```csharp
public String GetAdpEmployeeName(string emplId)
{
    if (emplId != null)
    {
        var employee =
            Factory.GetRepository<EmployeeData.Employee>().Query().FirstOrDefault(x => (x.Id == emplId));
        if (employee != null)
        {
            if (employee.PreferredName.IsNullOrWhiteSpace())
                return employee.LastName + ", " + employee.FirstName;
            return employee.LastName + ", " + employee.PreferredName;
        }
    }
    return string.Empty;
}
```

## 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.

```sql
-- Inferred from LINQ (NHibernate mapping translation); not concrete SQL
SELECT * FROM (
  SELECT
    E.EMPLID,
    E.RPT_MGR_EMPLID,
    E.FirstName, -- unresolved mapping: Employee.FirstName
    E.LastName, -- unresolved mapping: Employee.LastName
    E.PreferredName -- unresolved mapping: Employee.PreferredName
  FROM ADP_EMPLOYEE E
  WHERE E.EMPLID = :emplId
) WHERE ROWNUM <= 1
```

Translation notes:
- **Unresolved mapping (partial).** `EmployeeData.Employee` is not mapped in `Data/SAIF.Data.NHibernate/Mappings/**`. Legends queries run:
  - 1. `legends chat "Which NHibernate ClassMap maps the entity SAIF.Data.Model.Employees.Employee" --repo-type Framework --docgen --raw` → mapped in SAIF.Framework.Data.NHibernate to table `ADP_EMPLOYEE`.
  - 2. `legends chat "List every column of the ADP_EMPLOYEE table mapped by the Employee ClassMap" --library SAIF.Framework.Data.NHibernate --doc-type database-tables --docgen --raw`, repeated with `--doc-type api` → columns not enumerated.
  - 3. `legends search "EmployeeMap ADP_EMPLOYEE columns EMPLID FIRST_NAME LAST_NAME PREFERRED_NAME" --library SAIF.Framework.Data.NHibernate --docgen --top 10 --raw` → no column-level hit.
  - 4. `legends chat "What are the key and column details of the ADP_EMPLOYEE table section" --library SAIF.Framework.Data.NHibernate --doc-type database-tables --docgen --raw` → key `EMPLID`; self-reference `RPT_MGR_EMPLID` (reporting manager).
- Per the skill convention, the C# property names `FirstName`/`LastName`/`PreferredName` stand in for the unknown column names; no column name was invented. Any other columns mapped by the external `EmployeeMap` are unknown and are omitted from the select list.
- Dialect is Oracle10, as for every other repository, via `Factory.GetRepository<T>()`.

## Operations and processes

- [Legal case queries](../operations/legal-case-queries.md)

## Business rules

- [SD-BR-060 Case-to-claim resolution precedence](../business-rules.md#sd-br-060-case-to-claim-resolution-precedence)
- [SD-BR-061 Preferred employee name takes precedence](../business-rules.md#sd-br-061-preferred-employee-name-takes-precedence)

## Sources
- `Data/SAIF.Data/Queries/Legal/LegalQueryProvider.cs:94`
