C
C#3y ago
ogie1985

Entityframework .Select vs Mapping method [Answered]

Is the following the same or has it performance difference?
var myList = await _dbContext.SomeList.Select(x => new myDTO{...}.ToListAsync();
var myList = await _dbContext.SomeList.Select(x => new myDTO{...}.ToListAsync();
var myData = await _dbContext.SomeList.ToListAsync();
var myList = MapToMyDTO(myData);
var myData = await _dbContext.SomeList.ToListAsync();
var myList = MapToMyDTO(myData);
4 Replies
ogie1985
ogie1985OP3y ago
Also which one is prefered more.. ?
Angius
Angius3y ago
The first one will generate SQL that only fetches the necessary data The second one will fetch everything, and map the data afterwards Using .Select() before the query gets resolved will always result in less data being fetched, and fewer memory allocations
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Accord
Accord3y ago
✅ This post has been marked as answered!
Want results from more Discord servers?
Add your server