Proper way to set FilterToUse at runtime, so an exception doesn't cause a full table select?

Posts   
 
    
trevorg
User
Posts: 104
Joined: 15-Nov-2007
# Posted on: 25-Sep-2009 22:20:18   

I have a data control defined like so:

<llblgenpro:LLBLGenProDataSource ID="llbComputerApplication"   
                    DataContainerType="EntityCollection" runat="server" ThrowExceptionOnIllegalFieldInput="false"  
                    EntityCollectionTypeName="Talisman.VistaDesktopSurvey.Domain.CollectionClasses.ComputerApplicationCollection, Talisman.VistaDesktopSurvey.Domain">
                </llblgenpro:LLBLGenProDataSource>

In page_load, I had this code:

computerAppFilter.Add(ComputerApplicationFields.ComputerID = Me.xComputer.ComputerID)
Me.llbComputerApplication.FilterToUse = computerAppFilter

xComputer is a property on the form that loads a computer entity by pulling the ComputerID from the querystring. If this failed, I threw an exception, which properly is catched in the form load and processing stops. However, the page continues rendering, and since the FilterToUse never got set, the data controls (I have 3 like this) all did full select from the underlying table, causing a System.OutOfMemoryException.

So, my workaround for this was to put a bogus filter on the data control at the top of the page load:

Me.llbComputerApplication.FilterToUse = New PredicateExpression(ComputerApplicationFields.ComputerID = "xxxxxxxxxxxxxxxxxxxxxxxxx")

But, there must be a better way to do this....I feel like I am doing something wrong at a fundamental level.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 26-Sep-2009 04:41:34   

Hi Trevor,

  1. Are the filter set wrapped in a "If !IsPostBack" statement?

  2. Where are you throwing the exception?

  3. Where are you trapping the exception?

  4. Try putting CacheLocation on your LLBLGenProDataSource

David Elizondo | LLBLGen Support Team
trevorg
User
Posts: 104
Joined: 15-Nov-2007
# Posted on: 28-Sep-2009 16:14:22   

Hi Daelmo,

The exception is occurring here:

computerAppFilter.Add(ComputerApplicationFields.ComputerID = Me.[b]xComputer[/b].ComputerID)
Me.llbComputerApplication.FilterToUse = computerAppFilter

xComputer is a property on the form...an exception occurs when trying to instantiate the xComputer object, so no filter applies, and the form then continues to initialize the data controls, which do a full table select....so, it all makes sense, it is not a bug in the data control, but it seems there should be some smarter way of coding this.....basically, in this scenario, there MUST be a filter of some kind, otherwise I want the data control to not pull data, hence the workaround I applied. Is this realistically the best way to handle it?

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 28-Sep-2009 16:28:35   

You haven't answered all of David's questions.

Anyway, what you did is an acceptable solution.

But are you superessing the exception (catching it without re-thrwoing it). If you are doing so, then the form will continue loading as usual, and your workaround is the only way of stopping fetching the entire table.

I recommend that you re-factor the code to have a method which returns the ComputerId as follows (code in C#):

computerAppFilter.Add(ComputerApplicationFields.ComputerID = GetComputerId
());
this.llbComputerApplication.FilterToUse = computerAppFilter;
private string GetComputerId()
{
    var id = string.Empty;
    try{
        id = this.xComputer.ComputerID;
    }
    catch{
        id = "xxxxxxxxxxxxxxxx";
    }
}
trevorg
User
Posts: 104
Joined: 15-Nov-2007
# Posted on: 28-Sep-2009 16:30:27   

Ok, thanks!