0

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.

Martin Ongtangco
  • 22,657
  • 16
  • 58
  • 84
  • Did you use the latest EF Tools? Version 6,1,3 contains improvements to sql server schema discovery – ErikEJ Apr 09 '15 at 14:19
  • Hi Erik, afaik I've the latest EF tools. Any other leads? – Martin Ongtangco Apr 09 '15 at 14:22
  • Are you sure? It is a separate download post vs 2013 update 4 – ErikEJ Apr 09 '15 at 14:24
  • Can you post a link to the vsix? Thanks – Martin Ongtangco Apr 09 '15 at 14:35
  • It is a msi, but sure: http://blogs.msdn.com/b/adonet/archive/2015/03/10/ef6-1-3-rtm-available.aspx – ErikEJ Apr 09 '15 at 14:46
  • Cheers, I've got the latest 6.1.3 Entity Framework version from NuGet and I'm using the EF Power tools VS plug-in (https://visualstudiogallery.msdn.microsoft.com/72a60b14-1581-4b9b-89f2-846072eff19d/). I'll try this one out. – Martin Ongtangco Apr 09 '15 at 14:49
  • So I've installed the tools and attempted to re-generate the models & data context. I've compared the models, data context, and mapping data with the one I originally generated. They do not have any difference. It still does not populate the properties. How exactly does this help me? Thanks. – Martin Ongtangco Apr 09 '15 at 15:01
  • It is solved. Here's my answer: https://stackoverflow.com/questions/29542993/generic-unit-of-work-and-repository-pattern-does-not-load-related-entities/29543154#29543154 – Martin Ongtangco Apr 09 '15 at 23:20

0 Answers0