Reputation: 35
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;
}
all item has id and DateMatch, but item.Home, item.Guest, item.Result ==null
Upvotes: 0
Views: 66
Reputation: 459
Ensure to load the related objects. For example like this:
foreach (var item in matches.Include(x => x.Home).Include(x => x.Guest).Include(x => x.Result))
{
...
}
Upvotes: 1