实体框架`ThenInclude`返回一个集合,而不是所选集合的单个实体

时间:2020-01-02 22:23:13

标签: entity-framework-core

我试图在存储库中使用以下代码检索嵌套对象:

enter image description here

我在这里阅读了一些问题,他们都建议这应该返回单个值。我需要为每个gamesTime添加gameDay属性。

GamesDays模型:

public class GameDay
    {
        public string Id { get; set; }        
        public string GamesDay { get; set; }
        public string LeagueSessionScheduleId { get; set; }
        public ICollection<GameTime> GamesTimes { get; set; } = new Collection<GameTime>();

    }

GameTime模型:

 public class GameTime
    {
        public string Id { get; set; }
        public string GameDayId { get; set; }
        public DateTime GamesTime { get; set; }
    }

还有什么要做的吗?

它对我来说适用于其他模型,例如:

public async Task<List<SportType>> GetAllAsync(CancellationToken ct = default)
        {
            return await this._dbContext.SportTypes.Include(sportType => sportType.Leagues).ThenInclude(league => league.Teams).ToListAsync(ct);            

        }

SportType模型:

public class SportType
    {
        public string Id { get; set; }
        public string Name { get; set; }
        public  IEnumerable<League> Leagues { get; set; }
    }

0 个答案:

没有答案