Last active
December 17, 2015 20:59
-
-
Save anlai/5672028 to your computer and use it in GitHub Desktop.
Better way to write linq queries
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
// inline method | |
var students = ( | |
from student in RepositoryFactory.StudentRepository.Queryable | |
select new { FirstName = student.FirstName, LastName = student.LastName, FullName = string.Format("{0} {1}", student.FirstName, student.LastName) } | |
).ToList(); | |
// using the let key word, looks cleaner | |
var students = ( | |
from student in RepositoryFactory.StudentRepository.Queryable | |
let fullname = string.Format("{0} {1}", student.FirstName, student.LastName) | |
select new { FirstName = student.FirstName, LastName = student.LastName, FullName = fullname } | |
).ToList(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment