2011-05-03 4 views
0

Sharepoint 2010에 3 개의 목록이 있으며 목록을 가져 와서 작동시키는 코드가 있습니다. 내 문제는 내 페이지를로드하는 데 약 15 초가 걸린다는 점입니다. 저는 LINQ에서 Sharepoint 및 LINQ 로의 전반적인 순위 초보자입니다. 내 질문입니다 :이 코드를 더 빨리 실행할 수있는 방법이 있습니까?Sharepoint에 LINQ 최적화

   SeatingChartContext dc = new SeatingChartContext(SPContext.Current.Web.Url); 
       EntityList<Seating_chartItem> seatCharts = dc.GetList<Seating_chartItem>("seating_chart"); 
       EntityList<UsersItem> users = dc.GetList<UsersItem>("users"); 
       EntityList<Excluded_usersItem> exusers = dc.GetList<Excluded_usersItem>("excluded_users"); 
       // EntityList<LogsItem> logs = dc.GetList<LogsItem>("logs"); 

       List<Seating_chartItem> seatList = (from seat in seatCharts where seat.Room == 0 where seat.Floor == floor select seat).ToList(); 
       List <UsersItem> usersList = (from user in users select user).ToList(); 
       List <Excluded_usersItem> xusersList = (from xuser in exusers select xuser).ToList(); 

       var results = from seat in seatList 
           join user in usersList on 
           seat.User_id equals user.User_id 
           where seat.Room == 0 
           where seat.Floor == floor 
           where !(from xuser in xusersList select xuser.User_id).Contains(user.User_id) 
           select new 
             { 
              sid = seat.Seat_id, 
              icon = seat.Icon, 
              topCoord = seat.Top_coord, 
              leftCoord = seat.Left_coord, 
              name = user.Name, 
              phone = user.Phone, 
              mobile = user.Mobile, 
              content = seat.Content 
             }; 

이 코드를 사용하는 데 걸리는 시간은 절망적입니다.

감사합니다.

+0

@BrokenGlass : 고마워, 그건 완전히 속임수 였어. 내 코드를 다시 보았을 때 나는 두 개의 큰 섹션에서 그것을 썼다. 다시 한번 감사드립니다. – Corey

답변

1

한 즉시 일 : 당신은 내 xusersList 매번-쿼리 다시하는 당신의 조인

where !(from xuser in xusersList select xuser.User_id).Contains(user.User_id) 

var xusersList = (from xuser in exusers select xuser.User_id).ToList(); 
(즉, 당신이 필요로하는 유일한 방법이기 때문에) 대신에 단지 처음에만 사용자 ID를 추출

다음 직접 사용

where !xusersList.Contains(user.User_id) 

더 나은 - 귀하의 요청에 전에 유효한 사용자를 결정합니다

usersList = usersList.Where(user => !xusersList.Contains(user.User_id)) 
        .ToList(); 

지금 당신은 그냥 완전이 제거 할 수있는 쿼리에서 조건.

는 또한 조건이 보이는 곳이 불필요한 수 :

이미 seatList 이런 식으로 필터링 된 이후
where seat.Room == 0 
where seat.Floor == floor 

.

사실상 가장 많은 시간이 걸리는 것을보기 위해 성능 데이터를 기록해야한다고 했으니까요? 처음 목록이나 실제 join/linq 쿼리를 얻는 것입니까?