I\'m trying to select all the rows out of a database using entity framework for manipulation before they\'re sent to the form
var ptx = [modelname].[tablename]()
Old post I know, but using Select(x => x)
can be useful to split the EF Core (or even just Linq) expression up into a query builder.
This is handy for adding dynamic conditions.
For example:
public async Task GetUser(Guid userId, string userGroup, bool noTracking = false)
{
IQueryable queryable = _context.Users.Select(x => x);
if(!string.IsNullOrEmpty(userGroup))
queryable = queryable.Where(x => x.UserGroup == userGroup);
if(noTracking)
queryable = queryable.AsNoTracking();
return await queryable.FirstOrDefaultAsync(x => x.userId == userId);
}