ExcludeIncludeFieldsList with ASPxGridView

Posts   
 
    
spodgod
User
Posts: 14
Joined: 20-Sep-2007
# Posted on: 29-Jan-2009 16:42:18   

As in thread http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=15019 I'm trying to limit the fields loaded to a bound ASPxGridView by default, but load them all for the individual row when the grid is set to edit mode.

I'm trying to follow Walaa's advice:

You should disable LivePersistence and pass the ExcludeIncludeFieldsList collection to the fetch method in the PerformSelect event handler.

however it's not clear to me how to do this using the properties or methods of either the PerformSelectEventArgs2 or LLBLGenProDataSource2 classes.

Here's what I've got so far:

<dxwgv:ASPxGridView ID="gridMain" runat="server" DataSourceForceStandardPaging="true" SkinID="EditableAddDelete" AutoGenerateColumns="False" DataSourceID="dsMain" KeyFieldName="ID"
OnStartRowEditing="gridMain_StartRowEditing">
    <Columns>

    *removed for brevity*

    </Columns>
</dxwgv:ASPxGridView>

<llblgenpro:LLBLGenProDataSource2 ID="dsMain" runat="server" CacheLocation="ASPNetCache" EnablePaging="True" AdapterTypeName="LLBLGen.ConservationEvidence.DatabaseSpecific.DataAccessAdapter, LLBLGen.ConservationEvidenceDBSpecific" DataContainerType="EntityCollection" EntityFactoryTypeName="LLBLGen.ConservationEvidence.FactoryClasses.CaseWithAffiliationIDEntityFactory, LLBLGen.ConservationEvidence" OnPerformSelect="dsMain_PerformSelect">
</llblgenpro:LLBLGenProDataSource2>

protected ExcludeIncludeFieldsList GetExcludedFieldList()
{
    ExcludeIncludeFieldsList excludedFields = new ExcludeIncludeFieldsList();
    excludedFields.Add(CaseFields.Summary);
    excludedFields.Add(CaseFields.Action);
    excludedFields.Add(CaseFields.Consequences);
    excludedFields.Add(CaseFields.Background);
}

/// <summary>
/// include excluded fields when the row is edited
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void gridMain_StartRowEditing(object sender, DevExpress.Web.Data.ASPxStartRowEditingEventArgs e)
{
    List<int> entityIndex = dsMain.EntityCollection.FindMatches(CaseFields.ID = e.EditingKeyValue);
    if (entityIndex.Count > 0)
        using (DataAccessAdapter adapter = new DataAccessAdapter())
            adapter.FetchExcludedFields(dsMain.EntityCollection[entityIndex[0]], GetExcludedFieldList());
}

/// <summary>
/// exclude large fields from the collection bound to the grid
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void dsMain_PerformSelect(object sender, PerformSelectEventArgs2 e)
{
    // **************************************************
    // how do I plumb in the GetExcludedFieldList() here?
    // **************************************************
    
    e.
    dsMain.
}

Can you let me know if I'm on the right track and how I should finish off dsMain_PerformSelect?

LLBLGen Pro 2.5 Final, ASPxGridView 8.2.4, ASP.NET 2, Adapter, SQL Server 2005

Many thanks

Rich

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 29-Jan-2009 21:04:07   

ExcludeIncludeFields is really designed for excluding large blob columns, not for hiding fields that you may want to display anyway. From the look of your code the fields you are exluding are not blobs.

Personally I would just take the hit of loading them at the first, and just hide the values/columns from the user when displaying the grid.

spodgod
User
Posts: 14
Joined: 20-Sep-2007
# Posted on: 29-Jan-2009 23:30:27   

Thanks for the reply MTrinder.

The trouble is the fields I want to lazy load are all nvarchar(MAX), which can soon choke the bandwidth when you try loading 40 of them just to show a grid which doesn't actually display them.

I'm already hiding them declaratively as you suggest, but the page is unacceptably slow, which is why I'm trying to implement this solution. Both the docs and Walaa's post indicate that this is possible, in fact the docs use this very example as a sensible use of the ExcludeIncludeFieldsList. They just don't tell you how to do it when binding to a datasource (which I've got to imagine a fair number of LLBLGen users are doing).

Any help with how to do this would be gratefully received.

Thanks

Rich

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 30-Jan-2009 07:19:08   

spodgod wrote:

Can you let me know if I'm on the right track and how I should finish off dsMain_PerformSelect?

You are on the right track... Put this on your event handler:

protected void dsMain_PerformSelect(object sender, PerformSelectEventArgs2 e)
{
     using(DataAccessAdapter adapter = new DataAccessAdapter())
     {
          adapter.FetchEntityCollection(e.ContainedCollection, e.Filter, e.MaxNumberOfItemsToReturn, 
          e.Sorter, e.PrefetchPath, GetExcludedFieldList(), e.PageNumber, e.PageSize,);
     }
}

David Elizondo | LLBLGen Support Team