none
Long query cause System.StackOverflowException. RRS feed

  • Question

  • I have a very long query in Linq to Sql to populate DataGrid as follows:

     

    var query = from c in dc.Hotel_Meals_TBLs 
    select new
    {
      Code = c.HotelCodePrimary,
      CountryCode = c.CountryCode,
      CityCode = c.CityCode,
      HotelCode = c.HotelCode,
      Stars = c.StarCode,
      WWW = c.WWWCode,
      ABF = c.ABFCode,
      Location = c.LocationCode,
      Currency = c.CurrencyCode,
      CodeCode = c.HotelCode,
      No = c.NoCode,
      HotelName = c.HotelName,
      HFROM = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("High")).FirstOrDefault(a => a.HotelCodeID == c.HotelCodeID)._From,
      HTO = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("High")).FirstOrDefault(a => a.HotelCodeID == c.HotelCodeID)._To,
      HFROM2 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("High")).Skip(1).Take(1).First()._From,
      HTO2 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("High")).Skip(1).Take(1).First()._To,
      HFROM3 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("High")).Skip(2).Take(1).First()._From,
      HTO3 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("High")).Skip(2).Take(1).First()._To,
      HFROM4 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("High")).Skip(3).Take(1).First()._From,
      HTO4 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("High")).Skip(3).Take(1).First()._To,
      HFROM5 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("High")).Skip(4).Take(1).First()._From,
      HTO5 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("High")).Skip(4).Take(1).First()._To,
      HFROM6 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("High")).Skip(5).Take(1).First()._From,
      HTO6 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("High")).Skip(5).Take(1).First()._To,
      HFROM7 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("High")).Skip(6).Take(1).First()._From,
      HTO7 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("High")).Skip(6).Take(1).First()._To,
      HFROM8 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("High")).Skip(7).Take(1).First()._From,
      HTO8 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("High")).Skip(7).Take(1).First()._To,
      HFROM9 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("High")).Skip(8).Take(1).First()._From,
      HTO9 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("High")).Skip(8).Take(1).First()._To,
      HFROM10 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("High")).Skip(9).Take(1).First()._From,
      HTO10 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("High")).Skip(9).Take(1).First()._To,
      PFROM = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Peak")).FirstOrDefault(a => a.HotelCodeID == c.HotelCodeID)._From,
      PTO = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Peak")).FirstOrDefault(a => a.HotelCodeID == c.HotelCodeID)._To,
      PFROM2 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Peak")).Skip(1).Take(1).First()._From,
      PTO2 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Peak")).Skip(1).Take(1).First()._To,
      PFROM3 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Peak")).Skip(2).Take(1).First()._From,
      PTO3 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Peak")).Skip(2).Take(1).First()._To,
      PFROM4 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Peak")).Skip(3).Take(1).First()._From,
      PTO4 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Peak")).Skip(3).Take(1).First()._To,
      PFROM5 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Peak")).Skip(4).Take(1).First()._From,
      PTO5 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Peak")).Skip(4).Take(1).First()._To,
      PFROM6 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Peak")).Skip(5).Take(1).First()._From,
      PTO6 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Peak")).Skip(5).Take(1).First()._To,
      PFROM7 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Peak")).Skip(6).Take(1).First()._From,
      PTO7 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Peak")).Skip(6).Take(1).First()._To,
      PFROM8 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Peak")).Skip(7).Take(1).First()._From,
      PTO8 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Peak")).Skip(7).Take(1).First()._To,
      PFROM9 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Peak")).Skip(8).Take(1).First()._From,
      PTO9 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Peak")).Skip(8).Take(1).First()._To,
      PFROM10 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Peak")).Skip(9).Take(1).First()._From,
      PTO10 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Peak")).Skip(9).Take(1).First()._To,
      TPFROM = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("ExtraPeak")).FirstOrDefault(a => a.HotelCodeID == c.HotelCodeID)._From,
      TPTO = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("ExtraPeak")).FirstOrDefault(a => a.HotelCodeID == c.HotelCodeID)._To,
      TPFROM2 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("ExtraPeak")).Skip(1).Take(1).First()._From,
      TPTO2 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("ExtraPeak")).Skip(1).Take(1).First()._To,
      TPFROM3 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("ExtraPeak")).Skip(2).Take(1).First()._From,
      TPTO3 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("ExtraPeak")).Skip(2).Take(1).First()._To,
      SFROM = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Shoulder")).FirstOrDefault(a => a.HotelCodeID == c.HotelCodeID)._From,
      STO = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Shoulder")).FirstOrDefault(a => a.HotelCodeID == c.HotelCodeID)._To,
      SFROM2 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Shoulder")).Skip(1).Take(1).First()._From,
      STO2 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Shoulder")).Skip(1).Take(1).First()._To,
      SFROM3 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Shoulder")).Skip(2).Take(1).First()._From,
      STO3 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Shoulder")).Skip(2).Take(1).First()._To,
      LFROM = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Low")).FirstOrDefault(a => a.HotelCodeID == c.HotelCodeID)._From,
      LTO = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Low")).FirstOrDefault(a => a.HotelCodeID == c.HotelCodeID)._To,
      LFROM2 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Low")).Skip(1).Take(1).First()._From,
      LTO2 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Low")).Skip(1).Take(1).First()._To,
      LFROM3 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Low")).Skip(2).Take(1).First()._From,
      LTO3 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Low")).Skip(2).Take(1).First()._To,
      LFROM4 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Low")).Skip(3).Take(1).First()._From,
      LTO4 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Low")).Skip(3).Take(1).First()._To,
      LFROM5 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Low")).Skip(4).Take(1).First()._From,
      LTO5 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Low")).Skip(4).Take(1).First()._To,
      LFROM6 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Low")).Skip(5).Take(1).First()._From,
      LTO6 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Low")).Skip(5).Take(1).First()._To,
      LFROM7 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Low")).Skip(6).Take(1).First()._From,
      LTO7 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Low")).Skip(6).Take(1).First()._To,
      LFROM8 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Low")).Skip(7).Take(1).First()._From,
      LTO8 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Low")).Skip(7).Take(1).First()._To,
      LFROM9 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Low")).Skip(8).Take(1).First()._From,
      LTO9 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Low")).Skip(8).Take(1).First()._To,
      LFROM10 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Low")).Skip(9).Take(1).First()._From,
      LTO10 = c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("Low")).Skip(9).Take(1).First()._To,
      BF = c.Breakfast,
      LUN = c.Lunch,
      DIN = c.Dinner,
      _24Dec = c._24Dec,
      _31Dec = c._31Dec,
      ROOM1 = c.HotelRoom_TBLs.FirstOrDefault(a => a.HotelCodeID == c.HotelCodeID).RoomName,
      SGLH1 = c.HotelRoom_TBLs.FirstOrDefault(a => a.HotelCodeID == c.HotelCodeID).SGL_HighSeason,
      DBLH1 = c.HotelRoom_TBLs.FirstOrDefault(a => a.HotelCodeID == c.HotelCodeID).DBL_HighSeason,
      TPLH1 = c.HotelRoom_TBLs.FirstOrDefault(a => a.HotelCodeID == c.HotelCodeID).TPL_HighSeason,
      SGLP1 = c.HotelRoom_TBLs.FirstOrDefault(a => a.HotelCodeID == c.HotelCodeID).SGL_PeakSeason,
      DBLP1 = c.HotelRoom_TBLs.FirstOrDefault(a => a.HotelCodeID == c.HotelCodeID).DBL_PeakSeason,
      TPLP1 = c.HotelRoom_TBLs.FirstOrDefault(a => a.HotelCodeID == c.HotelCodeID).TPL_PeakSeason,
      SGLTP1 = c.HotelRoom_TBLs.FirstOrDefault(a => a.HotelCodeID == c.HotelCodeID).SGL_TopPeakSeason,
      DBLTP1 = c.HotelRoom_TBLs.FirstOrDefault(a => a.HotelCodeID == c.HotelCodeID).DBL_TopPeakSeason,
      TPLTP1 = c.HotelRoom_TBLs.FirstOrDefault(a => a.HotelCodeID == c.HotelCodeID).TPL_TopPeakSeason,
      SGLS1 = c.HotelRoom_TBLs.FirstOrDefault(a => a.HotelCodeID == c.HotelCodeID).SGL_ShoulderSeason,
      DBLS1 = c.HotelRoom_TBLs.FirstOrDefault(a => a.HotelCodeID == c.HotelCodeID).DBL_ShoulderSeason,
      TPLS1 = c.HotelRoom_TBLs.FirstOrDefault(a => a.HotelCodeID == c.HotelCodeID).TPL_ShoulderSeason,
      SGLL1 = c.HotelRoom_TBLs.FirstOrDefault(a => a.HotelCodeID == c.HotelCodeID).SGL_LowSeason,
      DBLL1 = c.HotelRoom_TBLs.FirstOrDefault(a => a.HotelCodeID == c.HotelCodeID).DBL_LowSeason,
      TPLL1 = c.HotelRoom_TBLs.FirstOrDefault(a => a.HotelCodeID == c.HotelCodeID).TPL_LowSeason,
      ROOM2 = c.HotelRoom_TBLs.Skip(1).Take(1).First().RoomName,
      SGLH2 = c.HotelRoom_TBLs.Skip(1).Take(1).First().SGL_HighSeason,
      DBLH2 = c.HotelRoom_TBLs.Skip(1).Take(1).First().DBL_HighSeason,
      TPLH2 = c.HotelRoom_TBLs.Skip(1).Take(1).First().TPL_HighSeason,
      SGLP2 = c.HotelRoom_TBLs.Skip(1).Take(1).First().SGL_PeakSeason,
      DBLP2 = c.HotelRoom_TBLs.Skip(1).Take(1).First().DBL_PeakSeason,
      TPLP2 = c.HotelRoom_TBLs.Skip(1).Take(1).First().TPL_PeakSeason,
      SGLTP2 = c.HotelRoom_TBLs.Skip(1).Take(1).First().SGL_TopPeakSeason,
      DBLTP2 = c.HotelRoom_TBLs.Skip(1).Take(1).First().DBL_TopPeakSeason,
      TPLTP2 = c.HotelRoom_TBLs.Skip(1).Take(1).First().TPL_TopPeakSeason,
      SGLS2 = c.HotelRoom_TBLs.Skip(1).Take(1).First().SGL_ShoulderSeason,
      DBLS2 = c.HotelRoom_TBLs.Skip(1).Take(1).First().DBL_ShoulderSeason,
      TPLS2 = c.HotelRoom_TBLs.Skip(1).Take(1).First().TPL_ShoulderSeason,
      SGLL2 = c.HotelRoom_TBLs.Skip(1).Take(1).First().SGL_LowSeason,
      DBLL2 = c.HotelRoom_TBLs.Skip(1).Take(1).First().DBL_LowSeason,
      TPLL2 = c.HotelRoom_TBLs.Skip(1).Take(1).First().TPL_LowSeason,
      ROOM3 = c.HotelRoom_TBLs.Skip(2).Take(1).First().RoomName,
      SGLH3 = c.HotelRoom_TBLs.Skip(2).Take(1).First().SGL_HighSeason,
      DBLH3 = c.HotelRoom_TBLs.Skip(2).Take(1).First().DBL_HighSeason,
      TPLH3 = c.HotelRoom_TBLs.Skip(2).Take(1).First().TPL_HighSeason,
      SGLP3 = c.HotelRoom_TBLs.Skip(2).Take(1).First().SGL_PeakSeason,
      DBLP3 = c.HotelRoom_TBLs.Skip(2).Take(1).First().DBL_PeakSeason,
      TPLP3 = c.HotelRoom_TBLs.Skip(2).Take(1).First().TPL_PeakSeason,
      SGLTP3 = c.HotelRoom_TBLs.Skip(2).Take(1).First().SGL_TopPeakSeason,
      DBLTP3 = c.HotelRoom_TBLs.Skip(2).Take(1).First().DBL_TopPeakSeason,
      TPLTP3 = c.HotelRoom_TBLs.Skip(2).Take(1).First().TPL_TopPeakSeason,
      SGLS3 = c.HotelRoom_TBLs.Skip(2).Take(1).First().SGL_ShoulderSeason,
      DBLS3 = c.HotelRoom_TBLs.Skip(2).Take(1).First().DBL_ShoulderSeason,
      TPLS3 = c.HotelRoom_TBLs.Skip(2).Take(1).First().TPL_ShoulderSeason,
      SGLL3 = c.HotelRoom_TBLs.Skip(2).Take(1).First().SGL_LowSeason,
      DBLL3 = c.HotelRoom_TBLs.Skip(2).Take(1).First().DBL_LowSeason,
      TPLL3 = c.HotelRoom_TBLs.Skip(2).Take(1).First().TPL_LowSeason,
      ROOM4 = c.HotelRoom_TBLs.Skip(3).Take(1).First().RoomName,
      SGLH4 = c.HotelRoom_TBLs.Skip(3).Take(1).First().SGL_HighSeason,
      DBLH4 = c.HotelRoom_TBLs.Skip(3).Take(1).First().DBL_HighSeason,
      TPLH4 = c.HotelRoom_TBLs.Skip(3).Take(1).First().TPL_HighSeason,
      SGLP4 = c.HotelRoom_TBLs.Skip(3).Take(1).First().SGL_PeakSeason,
      DBLP4 = c.HotelRoom_TBLs.Skip(3).Take(1).First().DBL_PeakSeason,
      TPLP4 = c.HotelRoom_TBLs.Skip(3).Take(1).First().TPL_PeakSeason,
      SGLTP4 = c.HotelRoom_TBLs.Skip(3).Take(1).First().SGL_TopPeakSeason,
      DBLTP4 = c.HotelRoom_TBLs.Skip(3).Take(1).First().DBL_TopPeakSeason,
      TPLTP4 = c.HotelRoom_TBLs.Skip(3).Take(1).First().TPL_TopPeakSeason,
      SGLS4 = c.HotelRoom_TBLs.Skip(3).Take(1).First().SGL_ShoulderSeason,
      DBLS4 = c.HotelRoom_TBLs.Skip(3).Take(1).First().DBL_ShoulderSeason,
      TPLS4 = c.HotelRoom_TBLs.Skip(3).Take(1).First().TPL_ShoulderSeason,
      SGLL4 = c.HotelRoom_TBLs.Skip(3).Take(1).First().SGL_LowSeason,
      DBLL4 = c.HotelRoom_TBLs.Skip(3).Take(1).First().DBL_LowSeason,
      TPLL4 = c.HotelRoom_TBLs.Skip(3).Take(1).First().TPL_LowSeason,
      ROOM5 = c.HotelRoom_TBLs.Skip(4).Take(1).First().RoomName,
      SGLH5 = c.HotelRoom_TBLs.Skip(4).Take(1).First().SGL_HighSeason,
      DBLH5 = c.HotelRoom_TBLs.Skip(4).Take(1).First().DBL_HighSeason,
      TPLH5 = c.HotelRoom_TBLs.Skip(4).Take(1).First().TPL_HighSeason,
      SGLP5 = c.HotelRoom_TBLs.Skip(4).Take(1).First().SGL_PeakSeason,
      DBLP5 = c.HotelRoom_TBLs.Skip(4).Take(1).First().DBL_PeakSeason,
      TPLP5 = c.HotelRoom_TBLs.Skip(4).Take(1).First().TPL_PeakSeason,
      SGLTP5 = c.HotelRoom_TBLs.Skip(4).Take(1).First().SGL_TopPeakSeason,
      DBLTP5 = c.HotelRoom_TBLs.Skip(4).Take(1).First().DBL_TopPeakSeason,
      TPLTP5 = c.HotelRoom_TBLs.Skip(4).Take(1).First().TPL_TopPeakSeason,
      SGLS5 = c.HotelRoom_TBLs.Skip(4).Take(1).First().SGL_ShoulderSeason,
      DBLS5 = c.HotelRoom_TBLs.Skip(4).Take(1).First().DBL_ShoulderSeason,
      TPLS5 = c.HotelRoom_TBLs.Skip(4).Take(1).First().TPL_ShoulderSeason,
      SGLL5 = c.HotelRoom_TBLs.Skip(4).Take(1).First().SGL_LowSeason,
      DBLL5 = c.HotelRoom_TBLs.Skip(4).Take(1).First().DBL_LowSeason,
      TPLL5 = c.HotelRoom_TBLs.Skip(4).Take(1).First().TPL_LowSeason,
      ROOM6 = c.HotelRoom_TBLs.Skip(5).Take(1).First().RoomName,
      SGLH6 = c.HotelRoom_TBLs.Skip(5).Take(1).First().SGL_HighSeason,
      DBLH6 = c.HotelRoom_TBLs.Skip(5).Take(1).First().DBL_HighSeason,
      TPLH6 = c.HotelRoom_TBLs.Skip(5).Take(1).First().TPL_HighSeason,
      SGLP6 = c.HotelRoom_TBLs.Skip(5).Take(1).First().SGL_PeakSeason,
      DBLP6 = c.HotelRoom_TBLs.Skip(5).Take(1).First().DBL_PeakSeason,
      TPLP6 = c.HotelRoom_TBLs.Skip(5).Take(1).First().TPL_PeakSeason,
      SGLTP6 = c.HotelRoom_TBLs.Skip(5).Take(1).First().SGL_TopPeakSeason,
      DBLTP6 = c.HotelRoom_TBLs.Skip(5).Take(1).First().DBL_TopPeakSeason,
      TPLTP6 = c.HotelRoom_TBLs.Skip(5).Take(1).First().TPL_TopPeakSeason,
      SGLS6 = c.HotelRoom_TBLs.Skip(5).Take(1).First().SGL_ShoulderSeason,
      DBLS6 = c.HotelRoom_TBLs.Skip(5).Take(1).First().DBL_ShoulderSeason,
      TPLS6 = c.HotelRoom_TBLs.Skip(5).Take(1).First().TPL_ShoulderSeason,
      SGLL6 = c.HotelRoom_TBLs.Skip(5).Take(1).First().SGL_LowSeason,
      DBLL6 = c.HotelRoom_TBLs.Skip(5).Take(1).First().DBL_LowSeason,
      TPLL6 = c.HotelRoom_TBLs.Skip(5).Take(1).First().TPL_LowSeason,
      ROOM7 = c.HotelRoom_TBLs.Skip(6).Take(1).First().RoomName,
      SGLH7 = c.HotelRoom_TBLs.Skip(6).Take(1).First().SGL_HighSeason,
      DBLH7 = c.HotelRoom_TBLs.Skip(6).Take(1).First().DBL_HighSeason,
      TPLH7 = c.HotelRoom_TBLs.Skip(6).Take(1).First().TPL_HighSeason,
      SGLP7 = c.HotelRoom_TBLs.Skip(6).Take(1).First().SGL_PeakSeason,
      DBLP7 = c.HotelRoom_TBLs.Skip(6).Take(1).First().DBL_PeakSeason,
      TPLP7 = c.HotelRoom_TBLs.Skip(6).Take(1).First().TPL_PeakSeason,
      SGLTP7 = c.HotelRoom_TBLs.Skip(6).Take(1).First().SGL_TopPeakSeason,
      DBLTP7 = c.HotelRoom_TBLs.Skip(6).Take(1).First().DBL_TopPeakSeason,
      TPLTP7 = c.HotelRoom_TBLs.Skip(6).Take(1).First().TPL_TopPeakSeason,
      SGLS7 = c.HotelRoom_TBLs.Skip(6).Take(1).First().SGL_ShoulderSeason,
      DBLS7 = c.HotelRoom_TBLs.Skip(6).Take(1).First().DBL_ShoulderSeason,
      TPLS7 = c.HotelRoom_TBLs.Skip(6).Take(1).First().TPL_ShoulderSeason,
      SGLL7 = c.HotelRoom_TBLs.Skip(6).Take(1).First().SGL_LowSeason,
      DBLL7 = c.HotelRoom_TBLs.Skip(6).Take(1).First().DBL_LowSeason,
      TPLL7 = c.HotelRoom_TBLs.Skip(6).Take(1).First().TPL_LowSeason,
      ROOM8 = c.HotelRoom_TBLs.Skip(7).Take(1).First().RoomName,
      SGLH8 = c.HotelRoom_TBLs.Skip(7).Take(1).First().SGL_HighSeason,
      DBLH8 = c.HotelRoom_TBLs.Skip(7).Take(1).First().DBL_HighSeason,
      TPLH8 = c.HotelRoom_TBLs.Skip(7).Take(1).First().TPL_HighSeason,
      SGLP8 = c.HotelRoom_TBLs.Skip(7).Take(1).First().SGL_PeakSeason,
      DBLP8 = c.HotelRoom_TBLs.Skip(7).Take(1).First().DBL_PeakSeason,
      TPLP8 = c.HotelRoom_TBLs.Skip(7).Take(1).First().TPL_PeakSeason,
      SGLTP8 = c.HotelRoom_TBLs.Skip(7).Take(1).First().SGL_TopPeakSeason,
      DBLTP8 = c.HotelRoom_TBLs.Skip(7).Take(1).First().DBL_TopPeakSeason,
      TPLTP8 = c.HotelRoom_TBLs.Skip(7).Take(1).First().TPL_TopPeakSeason,
      SGLS8 = c.HotelRoom_TBLs.Skip(7).Take(1).First().SGL_ShoulderSeason,
      DBLS8 = c.HotelRoom_TBLs.Skip(7).Take(1).First().DBL_ShoulderSeason,
      TPLS8 = c.HotelRoom_TBLs.Skip(7).Take(1).First().TPL_ShoulderSeason,
      SGLL8 = c.HotelRoom_TBLs.Skip(7).Take(1).First().SGL_LowSeason,
      DBLL8 = c.HotelRoom_TBLs.Skip(7).Take(1).First().DBL_LowSeason,
      TPLL8 = c.HotelRoom_TBLs.Skip(7).Take(1).First().TPL_LowSeason,
      CivicNumber =c.Number,
      Street =c.Street,
      District =c.District,
      City =c.City,
      Country =c.Country,
      Tel =c.Tel,
      Fax =c.Fax,
      TotalRoom =c.TotalRoom,
      RoomFacilities =c.RoomFacilities,
      RestaurantBar =c.Restaurant_Bar,
      HotelFacilities =c.HotelFacilities,
      GM = c.HotelContact_TBLs.Where(d => d.ContactType.Contains("GM")).SingleOrDefault(a => a.HotelCodeID == c.HotelCodeID).Name,
      GMMobile = c.HotelContact_TBLs.Where(d => d.ContactType.Contains("GM")).SingleOrDefault(a => a.HotelCodeID == c.HotelCodeID).Mobile,
      GMDirectTel = c.HotelContact_TBLs.Where(d => d.ContactType.Contains("GM")).SingleOrDefault(a => a.HotelCodeID == c.HotelCodeID).DirectTel,
      GMDirectFax = c.HotelContact_TBLs.Where(d => d.ContactType.Contains("GM")).SingleOrDefault(a => a.HotelCodeID == c.HotelCodeID).DirectFax,
      GMEmail = c.HotelContact_TBLs.Where(d => d.ContactType.Contains("GM")).SingleOrDefault(a => a.HotelCodeID == c.HotelCodeID).Email,
      DirectorFB = c.HotelContact_TBLs.Where(d => d.ContactType.StartsWith("Dir")).SingleOrDefault(a => a.HotelCodeID == c.HotelCodeID).Name,
      DirMobile = c.HotelContact_TBLs.Where(d => d.ContactType.StartsWith("Dir")).SingleOrDefault(a => a.HotelCodeID == c.HotelCodeID).Mobile,
      DirEmail = c.HotelContact_TBLs.Where(d => d.ContactType.StartsWith("Dir")).SingleOrDefault(a => a.HotelCodeID == c.HotelCodeID).Email,
      DOS = c.HotelContact_TBLs.Where(d => d.ContactType.StartsWith("DOS")).SingleOrDefault(a => a.HotelCodeID == c.HotelCodeID).Name,
      DOSMobile = c.HotelContact_TBLs.Where(d => d.ContactType.StartsWith("DOS")).SingleOrDefault(a => a.HotelCodeID == c.HotelCodeID).Mobile,
      DOSEmail = c.HotelContact_TBLs.Where(d => d.ContactType.StartsWith("DOS")).SingleOrDefault(a => a.HotelCodeID == c.HotelCodeID).Email,
      DOSSkype = c.HotelContact_TBLs.Where(d => d.ContactType.StartsWith("DOS")).SingleOrDefault(a => a.HotelCodeID == c.HotelCodeID).Skype,
      SM = c.HotelContact_TBLs.Where(d => d.ContactType.StartsWith("SM")).SingleOrDefault(a => a.HotelCodeID == c.HotelCodeID).Name,
      SMMobile = c.HotelContact_TBLs.Where(d => d.ContactType.StartsWith("SM")).SingleOrDefault(a => a.HotelCodeID == c.HotelCodeID).Mobile,
      SMEmail = c.HotelContact_TBLs.Where(d => d.ContactType.StartsWith("SM")).SingleOrDefault(a => a.HotelCodeID == c.HotelCodeID).Email,
      SMSkype =c.HotelContact_TBLs.Where(d => d.ContactType.StartsWith("SM")).SingleOrDefault(a => a.HotelCodeID == c.HotelCodeID).Skype,
      RSVN = c.HotelContact_TBLs.Where(d => d.ContactType.StartsWith("RSVN")).SingleOrDefault(a => a.HotelCodeID == c.HotelCodeID).Name,
      RSVNMobile =c.HotelContact_TBLs.Where(d => d.ContactType.StartsWith("RSVN")).SingleOrDefault(a => a.HotelCodeID == c.HotelCodeID).Mobile,
      RSVNEmail =c.HotelContact_TBLs.Where(d => d.ContactType.StartsWith("RSVN")).SingleOrDefault(a => a.HotelCodeID == c.HotelCodeID).Email,
      RSVNSkype =c.HotelContact_TBLs.Where(d => d.ContactType.StartsWith("RSVN")).SingleOrDefault(a => a.HotelCodeID == c.HotelCodeID).Skype,
      FocPolicy = c.FocPolicy,
      ChildPolicy = c.ChildPolicy,
      HoneyMoon = c.HoneyMoon,
      CancellationPolicy = c.CancellationPolicy,
      PaymentTerm = c.PaymentTerm,
      BankReference = c.BankReference,
      Notes = c.Note
    }
    

     

     

    but when I compile it with Visual Studio 2010 I receive this error message:

    An unhandled exception of type 'System.StackOverflowException' occurred in Anonymously Hosted DynamicMethods Assembly;{Cannot evaluate expression because the current thread is in a stack overflow state.}

    I compiled this query also with LinqPad4 and there was no errors, do you have any idea what does this message mean?

     

    I forgot in this query there are 4 Tables to join and populate a DataGrid :

    1 - Hotel_Meals_TBL ; HotelCodeID (PK)

    2 - HotelPeriod_TBL ;  HotelCodeID (FK)

    3 - HotelRoom_TBL ;  HotelCodeID (FK)

    4 - HotelContact_TBL ; HotelCodeID (FK)

     

    Thanks so much for your attention.

    Cheers

     

    Monday, July 4, 2011 1:33 AM

Answers

  • Hi again,

    Try may be with something like this:

    var query1 = from c in dc.Hotel_Meals_TBLs
              select new{...}
    
    var query2 = from c in dc.HotelPeriod_TBLs
              select new{...}
    
    var query3 = from c in dc.HotelRoom_TBLs 
              select new{...}
    
    var query4 = from c in dc.Hotel_Contact_TBLs 
              select new{...}
    
    
    

    Is that possible?

    If it is, does any of these queries still gives an error?

    Regards,

    JA Reyes.


    Please remember to Vote & "Mark As Answer" if this post is helpful to you.
    Por favor, recuerda Votar y "Marcar como respuesta" si la solución de esta pregunta te ha sido útil.
    Monday, July 4, 2011 9:38 AM
  • Hello,

    Thank you for posting.

    From your post, I have some suggestions to you as follows.

    1. Like JA Reyes said, I suggest you can consider re-designing the structor of your project, seperating the procedure codes and result codes. You can try to directly assign the result into proper column.

    2. I suggest you can try to change the stack size of your entire program. Like editbin.exe /STACK:<stacksize> file.exe Please check here for more information. http://msdn.microsoft.com/en-us/library/35yc2tc3(v=VS.100).aspx

    Hope this helps. Please feel free to let us know how it goes.

    Best Regards,


    Larcolais Gong[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, July 6, 2011 8:15 AM

All replies

  • Hi,

    May be you should try to divide your query in 4 sub-queries first, for simplicity and clarity. If this doesn't gives you any error, then you could try to join all your fields together again. 

    If an error persists, give more information about if this is produced by the join process of by a concrete sub-query.

    Regards,

    JA Reyes.


    Please remember to Vote & "Mark As Answer" if this post is helpful to you.
    Por favor, recuerda Votar y "Marcar como respuesta" si la solución de esta pregunta te ha sido útil.
    Monday, July 4, 2011 9:05 AM
  • Hi mr. Reyes,

    i wrote down also in this way :

    
    
    var query = from c in dc.Hotel_Meals_TBLs join p in 
    
    dc.HotelPeriod_TBLs on c.HotelCodeID equals p.HotelCodeID join r in 
    
    dc.HotelRoom_TBLs on c.HotelCodeID equals r.HotelCodeID join f in 
    
    dc.HotelPeriod_TBLs on c.HotelCodeID equals f.HotelCodeID group p 
    
    by c.HotelCodeID into g select new{...}
    
    

    but i receive the same error.

    I will try another way also if i see it is a complex query to do.

    thanks mr.Reyes

    Monday, July 4, 2011 9:27 AM
  • Hi again,

    Try may be with something like this:

    var query1 = from c in dc.Hotel_Meals_TBLs
              select new{...}
    
    var query2 = from c in dc.HotelPeriod_TBLs
              select new{...}
    
    var query3 = from c in dc.HotelRoom_TBLs 
              select new{...}
    
    var query4 = from c in dc.Hotel_Contact_TBLs 
              select new{...}
    
    
    

    Is that possible?

    If it is, does any of these queries still gives an error?

    Regards,

    JA Reyes.


    Please remember to Vote & "Mark As Answer" if this post is helpful to you.
    Por favor, recuerda Votar y "Marcar como respuesta" si la solución de esta pregunta te ha sido útil.
    Monday, July 4, 2011 9:38 AM
  • I tried to do divide the query in  4 sub query and it doesn't give any error, i am finding out the solution because i have others query to develop like this one .
    Monday, July 4, 2011 10:11 AM
  • Ok,

    And can you now join all queries in order to build your original select new{...} statement?


    Please remember to Vote & "Mark As Answer" if this post is helpful to you.
    Por favor, recuerda Votar y "Marcar como respuesta" si la solución de esta pregunta te ha sido útil.
    Monday, July 4, 2011 10:15 AM
  • Hi Reyes,

    i tried to follows your advice and i can join all subquery in one query and select new but i have a trouble to set up the Skip() and Take() in the HotelPeriod_Tbl and organize it in the best way,i continue to code and let you know about the result.

    Monday, July 4, 2011 11:10 AM
  • Hello,

    i am trying to work out this query following your advice but at the end i receive always the same error as follows :

     

    An unhandled exception of type 'System.StackOverflowException' occurred in Anonymously Hosted DynamicMethods Assembly;{Cannot evaluate expression because the current thread is in a stack overflow state.}

     

    I tried different way to develop it also with some subquery but not luck .;(

    Wednesday, July 6, 2011 1:05 AM
  • Well,

    Try to go commenting chunks of "select" parameters code in order to detect the source of the problem. Knowing the concrete line causing the problem will be easier to solve it.

    Regards,

    JA Reyes.


    Please remember to Vote & "Mark As Answer" if this post is helpful to you.
    Por favor, recuerda Votar y "Marcar como respuesta" si la solución de esta pregunta te ha sido útil.
    Wednesday, July 6, 2011 6:28 AM
  • Hello,

    Thank you for posting.

    From your post, I have some suggestions to you as follows.

    1. Like JA Reyes said, I suggest you can consider re-designing the structor of your project, seperating the procedure codes and result codes. You can try to directly assign the result into proper column.

    2. I suggest you can try to change the stack size of your entire program. Like editbin.exe /STACK:<stacksize> file.exe Please check here for more information. http://msdn.microsoft.com/en-us/library/35yc2tc3(v=VS.100).aspx

    Hope this helps. Please feel free to let us know how it goes.

    Best Regards,


    Larcolais Gong[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, July 6, 2011 8:15 AM