using (var db = new ConnectToDB())
{
var matches = db.Matches;
var matchesToReturn = new List<SimpleMatch>();
foreach (var item in matches)
{
var match = new SimpleMatch();
match.Id = item.Id;
match.Home = item.Home.Name;
match.Guest = item.Guest.Name;
match.HomeTeamGoals = item.Result.HomeTeamGoals;
match.GuestTeamGoals = item.Result.GuestTeamGoals;
matchesToReturn.Add(match);
}
return matchesToReturn;
}
todos os itens têm id e DateMatch, mas item.Home, item.Guest, item.Result == null
Certifique-se de carregar os objetos relacionados. Por exemplo, assim:
foreach (var item in matches.Include(x => x.Home).Include(x => x.Guest).Include(x => x.Result))
{
...
}
Este artigo é coletado da Internet.
Se houver alguma infração, entre em [email protected] Delete.
deixe-me dizer algumas palavras