Question

I have a page that binds data from an EntityDataSource to a paged ASP.NET ListView. The query is actually a fairly complex query and I don't know that an EDS is really the way to go but it's inherited code and I am hoping to resolve this issue without having to re-engineer the page completely.

The problem is that when the page is Posted Back, with a filter parameter, the query executes once without the filter and then once again with the filter. The problem is that the unfiltered resultset is 17+ million records and times the request out.

So my question is ...

  1. Why is the query executing twice? I thought that it might have had something to do with the DataPager on the ListView but when I removed it from the page it didn't change anything.

Update: 2013/04/16

Thank you @bUKaneer and @lthibodeaux. I thought it would behelpful to add the request information to the OP.

As suggested, I commented out Pager control(s) and list view. Upon their removal all requests to the database stopped. I added back just the ListView and the query was executing twice again.

There are no additional event handlers assigned to the EDS itself.

<asp:EntityDataSource ID="edsSerialNumbers" runat="server" ContextTypeName="DBName.Entities" EnableFlattening="False" 
                      EntitySetName="DIST_TABLE" Include="PRODUCT, DISTRIBUTION, DISTRIBUTION.COMPANY_SITE" 
                      EnableUpdate ="true" EnableViewState="true"
                      OrderBy="it.DISTRIBUTION.DIST_NAME, it.PRODUCT.SERIAL_NUMBER"></asp:EntityDataSource>

The DataPager is actually embedded in a separate UserControl that is included outside of the ListView, and is included twice ...

<div class="dataTablePager">
    <kqp:TablePager ID="pgrTop" runat="server" PagedControlID="lvSerialNumbers"/>
</div>

 <asp:ListView ID="lvSerialNumbers" runat="server" DataKeyNames="ID" OnDataBound="lvSerialNumbers_DataBound" OnItemEditing ="lvSerialNumbers_ItemEditing" onitemdatabound="lvSerialNumbers_ItemDataBound" EnableViewState="true">
            ...

</asp:ListView>

<div class="dataTablePager">
    <kqp:TablePager ID="pgrBot" runat="server" PagedControlID="lvSerialNumbers"/>
</div>

The only place in the code behind that the EDS is touched is here in the PreRender phase...

protected void Page_PreRender(object sender, EventArgs e)
{
    if (!kqpFilters.IsFiltered && !IsPostBack)
    {
        lvSerialNumbers.DataSourceID = null;            
    }
    else
    {
        lvSerialNumbers.DataSourceID = "edsSerialNumbers";
    }
}
Was it helpful?

Solution

After commenting EVERYTHING out except the spot where the ListView's datasource is assigned to the EDS I was unable to resolve this problem.

I will work around it by ripping out the EDS and replacing it it with a call to a stored procedure instead. Very frustrating though as this problem exists on about 10-15 screens and without an alternative I will have to re-write each, from the ground up.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top