In the example below there is a wrapper class for getting a single object as well as a list of objects. Instead of using the default complex types (such as SelectEmployeeByDepartment_Result or SelectEmployee_Result), LINQ is used to parse the results into a custom object.
public static List<Employee> GetEmployessFromDepartment(int departmentID) { var searchResults = new List<Employee>(); using (var entities = new EFEntities()) { try { searchResults = (from a in entities.SelectEmployeeByDepartment(departmentID) select (new Employee() { FirstName = a.first_name, SurName = a.surname, Title = a.job_title, Department = a.department_description, Phone = a.phone_number, Email = a.email_address })) .ToList(); } catch (Exception ex) { Log.Error(ex); throw; } } return searchResults; }
public static Employee GetEmployeeFromID(int employeeID) { var result = new Employee(); using (var entities = new EFEntities()) { try { result = (from a in entities.SelectEmployee(employeeID) select new Employee { FirstName = a.first_name, SurName = a.surname, Title = a.job_title, Department = a.department_description, Phone = a.phone_number, Email = a.email_address }) .SingleOrDefault(); } catch (Exception ex) { Log.Error(ex); throw; } } return result; }Business logic and other rules can also be placed at this layer (such as converting a SQL bit column into a C# bool object).