LivePersistence=false filter problem

Posts   
 
    
navakas
User
Posts: 8
Joined: 15-Nov-2008
# Posted on: 21-Aug-2010 00:03:36   

I am struggling to get an LLBLGenProDatasource (self servicing) to work in LivePersistence=false mode. I suspect I am missing something obvious, but I am an LLBL noob. Love the product, though simple_smile

I have a devexpress grid bound to LLBLGenProDatasource1. The database table it is bound to has about 3 million rows, so I only want to populate it with a filtered set.

Everything works perfectly if I have livepersistence=true, and do a filter on initial page load that returns no data, then apply filter criteria on a button click event. Impressive server side paging with efficient queries, very fast - love it.

This is the code: In the aspx:

<llblgenpro:LLBLGenProDataSource ID="LLBLGenProDataSource1" runat="server" 
    DataContainerType="EntityCollection" EntityCollectionTypeName="busphones.CollectionClasses.YellowFedCollection, busphones" 
       EnablePaging="True">
</llblgenpro:LLBLGenProDataSource>

 <dx:ASPxGridView ID="ASPxGridView1" runat="server" 
    AutoGenerateColumns="False" DataSourceID="LLBLGenProDataSource1" 
        DataSourceForceStandardPaging="True">
        <Columns>
            <dx:GridViewDataTextColumn FieldName="Addr1" VisibleIndex="0">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn FieldName="Addr2" VisibleIndex="1">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn FieldName="Category" VisibleIndex="2">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn FieldName="Company" VisibleIndex="3">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn FieldName="Electorate" VisibleIndex="4">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn FieldName="Email" VisibleIndex="5">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn FieldName="Fax1" VisibleIndex="6">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn FieldName="Fax2" VisibleIndex="7">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn FieldName="FederalElc" VisibleIndex="8">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn FieldName="Latitude" VisibleIndex="9">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn FieldName="Longitude" 
                VisibleIndex="10">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn FieldName="Phone" VisibleIndex="11">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn FieldName="Postcode" VisibleIndex="12">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn FieldName="Region" VisibleIndex="13">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn FieldName="State" VisibleIndex="14">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn FieldName="Suburb" VisibleIndex="15">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn FieldName="Website" VisibleIndex="16">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn FieldName="YellowId" VisibleIndex="17">
            </dx:GridViewDataTextColumn>
        </Columns>
    </dx:ASPxGridView>

In the aspx.cs:

using System.Configuration;
using System.Text;
using SD.LLBLGen.Pro.ORMSupportClasses;
using busphones.TypedViewClasses; //the llbl class
using busphones.HelperClasses;


public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
        //returns no data, to keep grid empty
            PredicateExpression filter = new PredicateExpression();
        
            filter.Add(YellowFedFields.Company == "");
            filter.Add(YellowFedFields.region == "");
            LLBLGenProDataSource1.FilterToUse = filter;
        }
    }
        protected void btnSearch_Click(object sender, EventArgs e)
    {

        PredicateExpression filter = new PredicateExpression();
        filter.Add(new FieldLikePredicate(YellowFedFields.Company, null, txtCompany.Text.Trim() + "%"));
        filter.Add(YellowFedFields.region == ddlRegion.Text);

        LLBLGenProDataSource1.FilterToUse = filter;

        ASPxGridView1.DataBind();
    }

... etc

The above works perfectly.

I cant find a 'How To' in the docs, or samples (forgive my blindness if I missed it..), on how to set up the performselect code to acheive the same as above with livepersistence=false. I have tried heaps of options in the performselect handler, a variety of .Select(), .Databind(), on grid & datasource, refetch=true, etc & I never get any data into the grid.

Would it be possible to get a little code snippet of how to apply filter to the datasource, initiated by a button click? What code goes into the button click event? What is the code in the perform_select?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 21-Aug-2010 08:05:02   

You can find a code snippet for that in Databinding / Intercepting activity section. On that page look for the "Example using Perform Event handlers", there is the code.

If you need further assistance please post back.

David Elizondo | LLBLGen Support Team
navakas
User
Posts: 8
Joined: 15-Nov-2008
# Posted on: 23-Aug-2010 13:00:28   

Yes, I saw that example, but that has the parameters in the 'SelectParameters' declaration in the html page. I need to set the parameters in code behind. How do I do this? If I use the code pasted in from the example & run the page, I get 'Object reference not set to an instance of an object.'

What do I put in a button click event to set up a filter to be passed to the datasource? What code do I put into the performselect event? +++++++++++++++++++++++++

Ok, I found the problem - I had an inappropriate setting in a devexpress grid - all OK now. Sorry to bother you - my bad rage

Thanks for prompt response first up.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 23-Aug-2010 16:06:53   

Would it be possible to get a little code snippet of how to apply filter to the datasource, initiated by a button click? What code goes into the button click event? What is the code in the perform_select?

First of all you should not change what you already have in the button_click, if it was working in the LivePersistence=True mode.

All you have to do in the PerformSelect event handler is to fetch the e.ContainedCollection.

Using the information passed in the EventArgument varaiable e.

e.Filter, e.MaxNumberOfItemsToReturn, e.Sorter, e.Relations, e.PrefetchPath, e.PageNumber, e.PageSize

navakas
User
Posts: 8
Joined: 15-Nov-2008
# Posted on: 24-Aug-2010 13:39:14   

OK, I have done that & now is partially working. I cannot get paging to work. The DataContainerType of my LLBLGENProDatasource is TypedView.

In the PerformGetDbCount event:


protected void dsBusiness_PerformGetDbCount(object sender, PerformGetDbCountEventArgs e)
       {
//this line returns error  'Object reference not set to an instance of an object', as the object is  a TypedView, not collection.
        
 e.DbCount = e.ContainedCollection.GetDbCount(e.Filter);
       }

If I change the code to:

protected void dsBusiness_PerformGetDbCount(object sender, PerformGetDbCountEventArgs e)
       {
          e.DbCount = e.ContainedTypedView.GetDbCount(e.Filter);
       }

The IDE throws an error 'Error 4 'SD.LLBLGen.Pro.ORMSupportClasses.PerformGetDbCountEventArgs' does not contain a definition for 'ContainedTypedView' " Also, intellisense in the IDE does not have 'ContainedTypedView' as an option. It seems I cannot get the dbcount for paging - how do I resolve this?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 24-Aug-2010 20:06:24   

Weird you receive that error. What LLBLGen version are you using? Do you have any other error in the compiler error list?

David Elizondo | LLBLGen Support Team
navakas
User
Posts: 8
Joined: 15-Nov-2008
# Posted on: 26-Aug-2010 04:32:14   

No other errors - project compiles & runs OK. I just downloaded latest build of 3.0 & redid the project - same problem. Attached 2 screen shots (in 1 image) showing missing TypedView option in the dbcount method, and present in the performselect.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 26-Aug-2010 10:20:27   

This is not a mistake.

To do a get dbcount for a typedlist (or typedview) do:

protected void LLBLGenProDataSource1_PerformGetDbCount(object sender, SD.LLBLGen.Pro.ORMSupportClasses.PerformGetDbCountEventArgs e)
{
    TypedListDAO dao = new TypedListDAO();
    e.DbCount = dao.GetDbCount(e.Fields, null, e.Filter, e.Relations, e.GroupBy, e.AllowDuplicates);
} 

ref: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=7239&StartAtMessage=0&#39928