LLBLGenProDataSource and EntityCollection

Posts   
 
    
Darren166
User
Posts: 41
Joined: 30-Jan-2007
# Posted on: 30-Jan-2007 05:28:46   

I am trying to set the entitycollection of a datasource by using

        LampSpecCollection LampSpecs = new LampSpecCollection();
        IPredicate filter = (LampSpecFields.LampSpecId == 2);
        LampSpecs.GetMulti(filter);
        LLBLGenProDataSource1.EntityCollection = LampSpecs;

The datasource is tied to a gridview.

I can monitor the SQL and I see that the correct SQL is being applied and filtering on LampSpecId = 2, however straight after that another SQL statement is sent as a SQL:BatchStarting that retrieves the entire table and that is used to fill the gridview.

There is no other code in the project. I am using the Dec 6th final 2.0 build with asp.net 2

Why is the Gridview displaying the entire table instead of just the items with LampSpecId = 2?

Darren

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 30-Jan-2007 08:06:19   

LLBLGenProDataSource performs the fetch itself if LivePersistence is set to true. So you should set the LLBLGenProDataSource.FilterToUse to the appropriate filter.

And if you want to perform the fetch yourself you shoulf set the LivePersistence property to false and handle the appropriate events. Please check LivePersistence and events in the LLBLGen Pro Manual: "Using the generated code -> SelfServicing -> Databinding with ASP.NET 2.0"

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 30-Jan-2007 10:07:03   

Darren166 wrote:

I am trying to set the entitycollection of a datasource by using

        LampSpecCollection LampSpecs = new LampSpecCollection();
        IPredicate filter = (LampSpecFields.LampSpecId == 2);
        LampSpecs.GetMulti(filter);
        LLBLGenProDataSource1.EntityCollection = LampSpecs;

The datasource is tied to a gridview.

I can monitor the SQL and I see that the correct SQL is being applied and filtering on LampSpecId = 2, however straight after that another SQL statement is sent as a SQL:BatchStarting that retrieves the entire table and that is used to fill the gridview.

There is no other code in the project. I am using the Dec 6th final 2.0 build with asp.net 2

Why is the Gridview displaying the entire table instead of just the items with LampSpecId = 2? Darren

The reason for this is that the grid gets rebound to the datasourcecontrol by asp.net and then asks for data, as the filter isn't set in the datasourcecontrol it simply fetches all data.

So instead of your code above, you should do: LLBLGenProDataSource1.FilterToUse= new PredicateExpression(LampSpecFields.LampSpecId == 2);

(as Walaa described)

That's it. You set the filter, and when the grid asks for data, the datasourcecontrol will fetch the data requested with the filter you set. simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Darren166
User
Posts: 41
Joined: 30-Jan-2007
# Posted on: 30-Jan-2007 10:16:52   

Thanks for that, it's very helpful. How do I deal with a slightly different situation though. In the manual you mention the example of using customer.orders collection for the datasource which is something I would also like to do, but of course the same thing happens when the grid gets rebound and all the orders are displayed.

By the way, there is a small mistake at that point in the manual as you reference a property SetEntityCollection.

Thanks for your excellent support and a brilliant product.

Darren.

Aurelien avatar
Aurelien
Support Team
Posts: 162
Joined: 28-Jun-2006
# Posted on: 30-Jan-2007 15:10:52   

Hi,

Have you set the LivePersistence property to false ?

Cheers.

Darren166
User
Posts: 41
Joined: 30-Jan-2007
# Posted on: 30-Jan-2007 15:27:23   

No the LivePersistance is set to True. Is there no way for it to work if this is the case? Setting it to true cuts down on code when using gridview to edit.

Darren

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 31-Jan-2007 04:11:37   

You may be able to accomplish this if customer is selected somewhere else in the page and you are able to setup select parameters for the orders data source. Can you post more on your customer.Orders situation if this doesn't help.