问题
I'm not sure if I'm doing things wrong or EF has a bug. I followed this StackOverflow post but to my avail, it still failed to populate. The structure is basically the same.
I'm absolutely sure on the data since the keys match up to the data. Eventually, I ended up just manipulating the models in my Service layer just to populate the properties.
public TeamsService(IRepositoryAsync<Team> repo, IRepositoryAsync<AspNetUser> userRepo)
: base(repo)
{
_repo = repo;
_userRepo = userRepo;
}
public async Task<IEnumerable<Team>> GetAllTeams()
{
var teams = await _repo.Queryable().ToListAsync();
teams.ForEach(t => t.Creator = _userRepo.Find(t.CreatorId));
return teams;
}
This work around does the job just fine. The foreign key Id's are all integers, so I doubt it was having a mismatch.
来源:https://stackoverflow.com/questions/29540395/ef-reverse-engineer-code-first-does-not-populate-one-to-many-many-to-many-prop