Created
August 1, 2019 14:04
-
-
Save JohnMGant/e1b956e50b764d3f46afd3fe23a3a2e3 to your computer and use it in GitHub Desktop.
ORM examples
This file contains hidden or 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
| internal IEnumerable<Employee> GetEmployees1(string lastName) { | |
| var query = | |
| from emp in context.Employee | |
| where emp.LastName.StartsWith(lastName) | |
| orderby emp.LastName, emp.FirstName | |
| select new Employee { | |
| Id = emp.Id, | |
| Name = emp.FirstName + ' ' + emp.LastName, | |
| FavoriteColor = emp.FavoriteColor ?? "Green" | |
| }; | |
| return query.ToList(); | |
| } | |
| internal IEnumerable<Employee> GetEmployees2(string lastName) { | |
| var query = | |
| context.Employee | |
| .Where(emp => emp.LastName.StartsWith(lastName)) | |
| .OrderBy(emp => emp.LastName) | |
| .ThenBy(emp => emp.FirstName) | |
| .Select(emp => new Employee { | |
| Id = emp.Id, | |
| Name = emp.FirstName + ' ' + emp.LastName, | |
| FavoriteColor = emp.FavoriteColor ?? "Green" | |
| }); | |
| return query.ToList(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment