Created
March 21, 2014 02:53
-
-
Save RyanABailey/9678550 to your computer and use it in GitHub Desktop.
Entity Framework wrapper to return custom objects using LINQ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment