This is a migrated thread and some comments may be shown as answers.

Horrible Performance

1 Answer 99 Views
LINQ (LINQ specific questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
sitefinitysteve asked on 23 Aug 2010, 05:33 PM
Is this bad query syntax perhaps somewhere?....if I enable both of these I go from 1 second page load to 10 seconds.

protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e) {
/*
    var filtered = (from r in this.Requests
                    select new {
                        ApprovalID = r.SittingWithApprovalID,
                        SittingWithApprovalID = r.SittingWithApprovalID,                   
                        SittingWithApprovalChainLevel = r.SittingWithApprovalChainLevel,
                        CreateDate = r.SittingWithApproverCreatedDate,
                        StatusText = r.Status,
                        ResidentEmail = r.ResidentEmail
                    });
 
    debugLabel.Text = this.Email;
 
    ((RadGrid)source).DataSource = filtered.Distinct().OrderByDescending(x => x.CreateDate);
    */
}

    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) {
    /*
        if (e.Item is GridDataItem) {
            try {
                GridDataItem item = e.Item as GridDataItem;
 
                if (Request.QueryString["GUID"] != null) {
                    if (item["SittingWithApprovalID"].Text.ToString() == Request.QueryString["GUID"].ToString())
                        ((GridDataItem)e.Item).Display = false;
 
                    Guid approvalid = new Guid(item["SittingWithApprovalID"].Text);
                    //RTODataLayer.Approval approval = RTOHelper.RTOScope.Extent<RTODataLayer.Approval>().FirstOrDefault(x => x.ApprovalID == approvalid);
 
                    List<ViewAllRequest> dates = (from d in this.Requests
                                                  where d.Active != 'N' && d.SittingWithApprovalID == approvalid
                                                  select d).ToList();
 
                    int totalCount = dates.Count;
                    int expiredCount = 0;
                    foreach (RTODataLayer.ViewAllRequest date in dates) {
                        if (DateTime.Now > date.FromDate)
                            expiredCount++;
                    }
 
                    item["NoticeColumn"].Text = totalCount + " dates";
 
                    if (expiredCount > 0)
                        item["NoticeColumn"].Text += "<br /><span style='color:#c00300'>" + expiredCount + " are expired</span>";
                } else {
                    if (item["SittingWithApprovalID"].Text.ToString() == this.AlreadyViewingThisApprovalID)
                        ((GridDataItem)e.Item).Display = false;
                }
            }catch(Exception ex){
                 
            }
        }
*/
    }


private List<ViewAllRequest> _requests = null;
public List<ViewAllRequest> Requests{
    get{
        if (_requests == null) {
            RTODataLayer.Approver approver = null;
            if (Membership.GetUser() != null)
                approver = RTOHelper.RTOScope.Extent<RTODataLayer.Approver>().FirstOrDefault(x => x.MedportalUID == new Guid(Membership.GetUser().ProviderUserKey.ToString()));
 
            if (approver != null) {
                _requests = (from r in RTOHelper.RTOScope.Extent<RTODataLayer.ViewAllRequest>()
                            where (r.SittingWith.Contains(this.Email) || r.SittingWith.Contains(approver.ApproverName))
                                  && r.Status.Contains("Pending")
                            select r).ToList();
            } else {
                _requests = (from r in RTOHelper.RTOScope.Extent<RTODataLayer.ViewAllRequest>()
                            where (r.SittingWith.Contains(this.Email))
                                  && r.Status.Contains("Pending")
                            select r).ToList();
            }
        }
        return _requests;
    }
}

1 Answer, 1 is accepted

Sort by
0
Serge
Telerik team
answered on 24 Aug 2010, 04:32 PM
Hi Steve,

 From what I can see the only place where OpenAccess is called is in the Requests property. Also ToList is called which means that the query is executed immediately. I suggest tracking how much time is needed for the retrieval of this query's result. Can you please track the time using the stopwatch class? Just wrap the property getter with the stopwatch.Start() and stopwatch.Stop() calls and set a breakpoint after the stop. If this query is executed in a timely fashion the issue possibly lies in the ItemBound event. However both event actually will be working only with in-memory results which is usually pretty fast.

Please note that the ItemBound event is called for each item in the datagrid, so you might consider some kind of batching this operation. 

I am looking forward to your response and to resolving this issue.

Sincerely yours,
Serge
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
LINQ (LINQ specific questions)
Asked by
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
Answers by
Serge
Telerik team
Share this question
or