(Language Integrated Query)
var numbers = Enumerable.Range(1, 100); //1,2,...,100
//query syntax:
var query = from n in numbers
where n % 3 == 0
select n * 2;
var numbers = Enumerable.Range(1, 100);
//method syntax
var method = numbers
.Where(n => n % 3 == 0)
.Select(n => n * 2);
Initialization
Condition
Selection
// Select all EBs.
var ebs = (from e in _dataContext.EBs
select e).ToList();
Initialization
Condition
Selection
// Select all approved form submissions.
var formSubmissions = (from s in _dataContext.FormSubmissions
where s.status == FormSubmission.STATUS_APPROVED
select s).ToList();
// Load FormEB record.
var formEB = await (from r in _dataContext.FormEBs
where r.listing_job_id == listingJobId
&& r.fe_email == email
&& r.eb_id == ebId
select r).AsNoTracking().FirstAsync();
OPERATOR | DESCRIPTION |
---|---|
where | Returns values from the datasource based on a predicate function. |
AsNoTeacking() | returns a new query and the returned entities will not be cached by the context (DbContext or Object Context) |
FirstAsync() | Asynchronously returns the first element of the query that satisfies a specified condition. |
Initialization
Condition
Selection
// Get all photos for this EE.
var localEePhotos = localJobPhotos
.Where(x => x.uid == localEE.uid)
.ToList();
// Get all photos for this EE.
var localEePhotos = localJobPhotos
.Where(x => x.uid == localEE.uid)
.ToList();
OPERATOR | DESCRIPTION |
---|---|
.ToList() | Takes the elements from the given source and it returns a new List. The input would be converted to type List. |