////public async Task<<IEnumerable>GenericEvent> FindAllWithIncludes() ////{ //// return await this._nostradamusContext.Set<GenericEvent>().AsNoTracking() //// .Include(ge => ge.Noster) //// .Include(ge => ge.GenericPredictions).ToListAsync(); ////} public async Task <IEnumerable <GenericEventDto> > FindAllWithIncludes() { var genericEvent = await this._nostradamusContext.Set <GenericEvent>().AsNoTracking() .Include(ge => ge.Noster) .Include(ge => ge.GenericPredictions).ToListAsync(); NosterDto nosterDto = new NosterDto(); GenericPredictionDto[] genericPredictionDtos = new GenericPredictionDto[50]; var config = new MapperConfiguration(cfg => { cfg.CreateMap <Noster, NosterDto>(); cfg.CreateMap <GenericPrediction, GenericPredictionDto>(); }); IMapper iMapper = config.CreateMapper(); var GenericEventDtoList = genericEvent.Select(ge => new GenericEventDto { Id = ge.Id, CreatedBy = ge.CreatedBy, Title = ge.Title, Description = ge.Description, DateOccurs = ge.DateOccurs, Valid = ge.Valid, Active = ge.Active, Occurred = ge.Occurred, CreationDate = ge.CreationDate, NosterDto = iMapper.Map(ge.Noster, nosterDto), GenericPredictionDtos = iMapper.Map(ge.GenericPredictions, genericPredictionDtos) }); return(GenericEventDtoList); }
public async Task <IEnumerable <NosterDto> > FindAllWithIncludes() { var Noster = await this._nostradamusContext.Set <Noster>().AsNoTracking() .Include(n => n.NosterScore) .Include(n => n.GenericEvents) .Include(n => n.GenericPredictions) .ToListAsync(); GenericEventDto[] GenericEventDtos = new GenericEventDto[50]; NosterScoreDto nosterScoreDto = new NosterScoreDto(); GenericPredictionDto[] genericPredictionDtos = new GenericPredictionDto[50]; var config = new MapperConfiguration(cfg => { cfg.CreateMap <GenericEvent, GenericEventDto>(); cfg.CreateMap <NosterScore, NosterScoreDto>(); cfg.CreateMap <GenericPrediction, GenericPredictionDto>(); }); IMapper iMapper = config.CreateMapper(); var NosterDtoList = Noster.Select(n => new NosterDto { UserName = n.UserName, Email = n.Email, PhoneNumber = n.PhoneNumber, PhoneNumberConfirmed = n.PhoneNumberConfirmed, TwoFactorEnabled = n.TwoFactorEnabled, CreationDate = n.CreationDate, NosterScoreDto = iMapper.Map(n.NosterScore, nosterScoreDto), GenericEventDtos = iMapper.Map(n.GenericEvents, GenericEventDtos), GenericPredictionDtos = iMapper.Map(n.GenericPredictions, genericPredictionDtos) }); return(NosterDtoList); }