Reputation: 3688
Is there any way to specify which columns to retrieve when using SingleOrDefault
with Entity Framework?
Something like this:
_messageRepository.FirstOrDefaultAsync(input.Id).select(m => m.title, m.Id)
It would be a very heavy query if I want to return all data ..
Thanks
Upvotes: 2
Views: 3433
Reputation: 36483
Your pseudo code is not entirely clear, but you probably simply want something like:
var result = await _messageRepository.Where(m => m.Id == input.Id)
.Select(m => new { m.Title, m.Id })
.FirstOrDefaultAsync();
Upvotes: 11