C Sharp - Entity Framework Core

EF Core – Linq Syntax

Limit the number of records returned is done with the Take() method.

Here is an example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public IResult<List<WikiPageEntity>> GetAll()
{
try
{
return new Result<List<WikiPageEntity>>(_context
.WikiPages
.Take(2)
.ToList()
).ReturnSuccess("Retrieved all WikiPage records successfully");
}
catch (Exception e)
{
return new Result<List<WikiPageEntity>>().ReturnFail("Error");
}
throw new NotImplementedException();
}

take(2)

In this case, .take(2) is limiting the resultset to 2 records.