LLBLGenProDataSource2 & Custom Filtering

Posts   
 
    
jader201
User
Posts: 33
Joined: 20-Mar-2007
# Posted on: 09-Sep-2008 20:31:22   

I'm trying to do some customer filtering on a LLBLGenProDataSource2 without much luck. By "custom", I mean not using the SelectParameters collection.

I have a TextBox that will allow the user to enter some text, and then I want to filter my results using a FieldLikePredicate. My DS has LivePersistence disabled.

Here's my HTML:


      <asp:TextBox ID="FilterText" runat="server"></asp:TextBox>
      <asp:Button ID="Submit" runat="server" Text="Submit" />
      <asp:GridView 
        ID="TestGridView" runat="server" DataSourceID="TestDS" 
        AllowPaging="true" DataKeyNames="ContractNumber"
        PageSize="10">
        <PagerSettings Mode="NextPreviousFirstLast" />
      </asp:GridView>
      <llblgenpro:LLBLGenProDataSource2 ID="TestDS" runat="server" EnablePaging="true" LivePersistence="false"
        DataContainerType="EntityCollection" 
        AdapterTypeName="Components.DataAccessLayers.MyDatabase.DatabaseSpecific.DataAccessAdapter, 
        Components.DataAccessLayers.MyDatabaseDBSpecific"
        EntityFactoryTypeName="Components.DataAccessLayers.MyDatabase.FactoryClasses.ContractMasterEntityFactory, 
        Components.DataAccessLayers.MyDatabase"
        MaxNumberOfItemsToReturn="1000"
        OnPerformSelect="TestDS_PerformSelect" OnPerformGetDbCount="TestDS_PerformGetDbCount" 
        >
      </llblgenpro:LLBLGenProDataSource2>

Here is the code behind:


    protected void TestDS_PerformSelect(object sender, 
        SD.LLBLGen.Pro.ORMSupportClasses.PerformSelectEventArgs2 e)
    {
        using (DataAccessAdapter adapter = new DataAccessAdapter())
        {
            //e.Filter == null, so I cannot add PredicateExpressions:
            //e.Filter.PredicateExpression.Add(ContractMasterFields.SkuNumber % ("%" + FilterText.Text + "%"));

            //e.Filter is also read-only so I cannot create a new instance:
            //e.Filter = new RelationPredicateBucket();

            adapter.FetchEntityCollection(e.ContainedCollection, e.Filter,
                    e.MaxNumberOfItemsToReturn, e.Sorter, e.PrefetchPath, e.PageNumber, e.PageSize);
        }
    }

    protected void TestDS_PerformGetDbCount(object sender, PerformGetDbCountEventArgs2 e)
    {
        using(DataAccessAdapter adapter = new DataAccessAdapter())
        {
            e.DbCount = adapter.GetDbCount(e.ContainedCollection, e.Filter);
        }
    }

So, my questions:

1) What is the best way to define custom filtering using the LLBLGenProDataSource2 control, with LivePersistence disabled?

2) If I should, instead, be using the SelectParameters collection for this, how do I define a FieldLikePredicate on the ControlParameter?

3) Or, am I going about this completely wrong, and should do something different that either of the above?

Thanks in advance. Jerad

jader201
User
Posts: 33
Joined: 20-Mar-2007
# Posted on: 09-Sep-2008 23:04:57   

I found my answer on this thread:

http://www.llblgen.com/tinyforum/NewMessage.aspx?QuoteMessageID=35277&THreadID=6401

Otis wrote:

You can also rework your code if you like that more, your code crashes because you assume Filter has a value, but as you didn't set a filter, it crashes as it's null. So first add your filter to a RelationPredicateBucket, then simply use that relationpredicatebucket in teh FetchEntityCollection.

So my code is now:


    protected void TestDS_PerformSelect(object sender,
        SD.LLBLGen.Pro.ORMSupportClasses.PerformSelectEventArgs2 e)
    {
        using (DataAccessAdapter adapter = new DataAccessAdapter())
        {
            RelationPredicateBucket filter = new RelationPredicateBucket();
            filter.PredicateExpression.Add(ContractMasterFields.SkuNumber % ("%" + FilterText.Text + "%"));

            adapter.FetchEntityCollection(e.ContainedCollection, filter,
                    e.MaxNumberOfItemsToReturn, e.Sorter, e.PrefetchPath, e.PageNumber, e.PageSize);
        }
    }

This worked like a charm. simple_smile