2011-07-03 70 views
0

我在LINQ to SQL中的很長的查詢來填充數據網格如下:長的查詢原因System.StackOverflowException

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 
} 

但是當我與Visual Studio 2010編譯它,我收到此錯誤信息:

類型「System.StackOverflowException」的未處理的異常發生在匿名託管DynamicMethods大會; {因爲當前線程堆棧溢出狀態無法計算表達式。}

我編譯這個查詢也與LinqPad4並沒有錯誤,你知道這個消息是什麼意思?

+0

從哪種應用程序運行此查詢? WindowsForms應用程序或ASP.NET頁面?你能告訴我們你是如何從你的代碼執行查詢的嗎? –

+0

@JayJay - 你真的需要在網格中顯示如此多的列嗎? – Giorgi

+0

@Davide,嗨,先生,我正在開發一個WPF應用程序,查詢將完成如下:this.xamHotel.DataContext = query.ToList();填充DataGrid;無論如何,如果你需要更多的解釋,我會與你分享,謝謝 – JayJay

回答

0

我建議你重寫你的查詢,以減少內存分配。 看,在每行,你寫道:

c.HotelPeriod_TBLs.Where(d => d.PeriodName.Contains("High")) 
// equal lines of code here. 

我覺得這是你查詢的主要問題。嘗試將數據填充到一個查詢中或將此查詢移動到SQL層。這個怪物活不了很長時間,會產生很大的記憶問題。

+0

謝謝先生,我會控制它,並讓你知道結果後。 – JayJay

+0

你爲什麼認爲記憶是問題?該代碼行在哪裏有很多內存分配?該行甚至沒有執行,它被轉換爲SQL。 – svick

+0

我認爲在編譯LINQ到SQL命令的時刻恰恰出現了內存問題。 – VMAtm