✅ entity framework return all objects

Hello, If I use entity framework and I want to get all objects in my repository, what should I do? 1:
private IEnumerable<TrainName> GetTrainNames()
{
return _dbStorage.TrainNames;
}
private IEnumerable<TrainName> GetTrainNames()
{
return _dbStorage.TrainNames;
}
2:
private async Task<IEnumerable<TrainName>> GetTrainNames()
{
return await _dbStorage.TrainNames.ToListAsync();
}
private async Task<IEnumerable<TrainName>> GetTrainNames()
{
return await _dbStorage.TrainNames.ToListAsync();
}
Or something else?
4 Replies
Angius
Angius2y ago
2
Scottek utek
Scottek utekOP2y ago
dbcontext wont update if I use n1?
Angius
Angius2y ago
It won't update in either case, you're not updating anything But in the first case, the DbSet will not be pupulated If that's what you meant
Scottek utek
Scottek utekOP2y ago
yes ok thx

Did you find this page helpful?