0
 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

img return

Venedchuk
  • 35
  • 6

1 Answers1

1

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))
{
    ...
}
Udo
  • 449
  • 3
  • 13