Skip to content

Instantly share code, notes, and snippets.

@JohnMGant
Created August 1, 2019 14:04
Show Gist options
  • Select an option

  • Save JohnMGant/e1b956e50b764d3f46afd3fe23a3a2e3 to your computer and use it in GitHub Desktop.

Select an option

Save JohnMGant/e1b956e50b764d3f46afd3fe23a3a2e3 to your computer and use it in GitHub Desktop.
ORM examples
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