Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 仅当您访问该接口时,才会加载该接口。因此GetCountries().WithId(1)将对数据库进行1次调用,GetCountries().WithId(1)将对数据库进行2次调用。您的版本在任何情况下都会发出最大数量的db调用,还是我误解了什么? _Asp.net Mvc_Linq_Stack Overflow - Fatal编程技术网

Asp.net mvc 仅当您访问该接口时,才会加载该接口。因此GetCountries().WithId(1)将对数据库进行1次调用,GetCountries().WithId(1)将对数据库进行2次调用。您的版本在任何情况下都会发出最大数量的db调用,还是我误解了什么?

Asp.net mvc 仅当您访问该接口时,才会加载该接口。因此GetCountries().WithId(1)将对数据库进行1次调用,GetCountries().WithId(1)将对数据库进行2次调用。您的版本在任何情况下都会发出最大数量的db调用,还是我误解了什么? ,asp.net-mvc,linq,stack-overflow,Asp.net Mvc,Linq,Stack Overflow,仅当您访问该接口时,才会加载该接口。因此GetCountries().WithId(1)将对数据库进行1次调用,GetCountries().WithId(1)将对数据库进行2次调用。您的版本在任何情况下都会发出最大数量的db调用,还是我误解了什么? public ActionResult ShowCountry(int id) { Country country = _gameService.GetCountry(id); return View

仅当您访问该接口时,才会加载该接口。因此GetCountries().WithId(1)将对数据库进行1次调用,GetCountries().WithId(1)将对数据库进行2次调用。您的版本在任何情况下都会发出最大数量的db调用,还是我误解了什么?
    public ActionResult ShowCountry(int id)
    {
        Country country = _gameService.GetCountry(id);
        return View(country);
    }
    public Country GetCountry(int id)
    {
        return _gameRepository.GetCountries().WithCountryId(id).SingleOrDefault();
    }
    public IQueryable<Country> GetCountries()
    {
        var countries =  from c in _db.Countries
               select new Country
               {
                   Id = c.Id,
                   Name = c.Name,
                   ShortDescription = c.ShortDescription,
                   FlagImage = c.FlagImage,
                   Game = GetGames().Where(g => g.Id == c.GameId).SingleOrDefault(),
                   SubRegion = GetSubRegions().Where(sr => sr.Id == c.SubRegionId).SingleOrDefault(),
               };
        return countries;
    }
    public IQueryable<Game> GetGames()
    {
        var games = from g in _db.Games                   
               select new Game
               {
                   Id = g.Id,
                   Name = g.Name

               };
        return games;

    }
    public IQueryable<SubRegion> GetSubRegions()
    {
        return from sr in _db.SubRegions
               select new SubRegion
               {
                   Id = sr.Id,
                   Name = sr.Name,
                   ShortDescription = sr.ShortDescription,
                   Game = GetGames().Where(g => g.Id == sr.GameId).SingleOrDefault(),
                   Region = GetRegions().Where(r => r.Id == sr.RegionId).SingleOrDefault(),
                   Countries = new LazyList<Country>(GetCountries().Where(c => c.SubRegion.Id == sr.Id))
               };
    }