Add examples with selecting specific columns and using a DTO.
This commit is contained in:
parent
b715fd3150
commit
51eb8b117a
@ -123,4 +123,32 @@ async Task PrintTeamById(int id)
|
||||
{
|
||||
Console.WriteLine(teamBasedOnId.Name);
|
||||
}
|
||||
}
|
||||
|
||||
async Task SelectQuery()
|
||||
{
|
||||
var items = await context.Teams
|
||||
.Select(t => new { t.Name, t.CreatedDate })
|
||||
.ToListAsync();
|
||||
foreach (var item in items)
|
||||
{
|
||||
Console.WriteLine($"{item.Name} - {item.CreatedDate}");
|
||||
}
|
||||
}
|
||||
|
||||
async Task SelectQueryDTO()
|
||||
{
|
||||
var items = await context.Teams
|
||||
.Select(t => new TeamInfoDTO { Name = t.Name, Created = t.CreatedDate })
|
||||
.ToListAsync();
|
||||
foreach (var item in items)
|
||||
{
|
||||
Console.WriteLine($"{item.Name} - {item.Created}");
|
||||
}
|
||||
}
|
||||
|
||||
class TeamInfoDTO
|
||||
{
|
||||
public DateTime Created { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user