C Sharp - Linq - Where

You can add Where clauses to linq statements.

Here is an example

1
2
3
4
5
6
7
8
public IResult<List<NoteEntity>> GetAll(string companyKey)
{
return new Result<List<NoteEntity>>(_context.Notes
.Where (r => r.CompanyKey == companyKey)
.Include(r => r.NoteTypeEntity)
.ToList()
).ReturnSuccess(LogInformation("Retrieved all Notes records successfully"));
}

Notice the where clause

I think you put this before include for performance.

For an And statement use && instead of and.

For example

1
.Where (e => e.Id == id && e.CompanyKey == companyKey);