EF Reverse Engineer Code First does not populate one-to-many & many-to-many properties

主宰稳场 提交于 2020-02-08 09:38:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!