示例#1
0
        public IActionResult GetCities(bool includeRelations = true,
                                       bool UseLazyLoading   = true,
                                       bool UseAutoMapper    = true)
        {
            IQueryable <City> CityList = null;

            //var cityList1 = _repositoryWrapper.CityInfoRepositoryWrapper.FindAll(); ;

            if ((false == includeRelations) || (false == UseLazyLoading))
            {
                _repositoryWrapper.CityInfoRepositoryWrapper.DisableLazyLoading();
            }
            else  // true == includeRelations && true == UseLazyLoading
            {
                _repositoryWrapper.CityInfoRepositoryWrapper.EnableLazyLoading();
            }

            if (true == UseLazyLoading)
            {
                CityList = _repositoryWrapper.CityInfoRepositoryWrapper.FindAll();
            }
            else
            {
                CityList = _repositoryWrapper.CityInfoRepositoryWrapper.GetAllCities(includeRelations) as IQueryable <City>;
            }

            // Koden der er udkommenteret herunder er med for at vise, at man kan nå alle
            // wrappere fra alle controllers.
            //var LanguageEntities = _repositoryWrapper.LanguageRepositoryWrapper.FindAll();

            List <CityDto> CityDtos;

            if (true == UseAutoMapper)
            {
                CityDtos = _mapper.Map <IEnumerable <CityDto> >(CityList).ToList();
            }
            else
            {
                // Use Mapster
                CityDtos = CityList.Adapt <CityDto[]>().ToList();
            }

            //List<CityDto> CityDtos = _mapper.Map<IEnumerable<CityDto>>(CityList).ToList();
            //List<CityDto> CityDtos1 = cityList1.Adapt<CityDto[]>().ToList();

            var CityDtos2 = CityList.Adapt <CityDto[]>();

            CityDto CityDto_Object_Final = new CityDto();

            CityDto_Object_Final.Id = 0;
            //CityDto_Object_Final.Name = "Load Metode";
            CityDto_Object_Final.Name        = (true == UseAutoMapper ? "AutoMapper" : "Mapster");
            CityDto_Object_Final.Description = (true == UseLazyLoading ? "Lazy Loading" : "Eager Loading");

            CityDtos.Add(CityDto_Object_Final);

            return(Ok(CityDtos));
        }
 public static async Task <List <TResult> > ProjectToAsync <TResult>(this IQueryable @this) => await Task.Run(() => @this.Adapt <List <TResult> >());