Filtered collection and UpdateMulti

Posts   
 
    
tvoss avatar
tvoss
User
Posts: 192
Joined: 07-Dec-2003
# Posted on: 17-Mar-2004 19:09:35   

If I have a collection that was got by getmulti on a filter with 2nd parameter of 10,000, and use updatemulti on it with conditions, will the conditions apply only to the filtered collection of 10,000 elements, or the whole collection of getmulti(nothing)?

If the former, I can do efficient top 10,000 update, without looping.

In other words you would be doing the looping right?

So collection10000.updatemulti(oneRecord,nothing) could at most change 10000 records, right?

Ooooooops,,,I see that doesn't work,,,updatemulti's filter overrides everything. Would that be a cool feature to add??? sunglasses

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 17-Mar-2004 21:20:14   

UpdateMulti updates entities directly in the table, using a single Update statement. So if you first use a filter which fetches 1000 objects, you can then also use the filter to update those 1000 entities in the table directly using UpdateMulti.

But I assume you want to have them in memory anyway because for other purposes as well?

Frans Bouma | Lead developer LLBLGen Pro
tvoss avatar
tvoss
User
Posts: 192
Joined: 07-Dec-2003
# Posted on: 18-Mar-2004 18:54:40   

Just so you understand what I was getting at:

Yes I can use the filter in the UpdateMulti, but I can't use the top 1,000 that I can in GetMulti.

But I guess if there is no update top 1000 sql command that might be difficult to implementconfused

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 18-Mar-2004 20:27:46   

UpdateMulti in fact creates an UPDATE table SET ... WHERE ... statement. These statements don't have a construction where you can say 'do the first 1000 matching the WHERE clause'. The amount of objects to update should be limited by a filter.

Frans Bouma | Lead developer LLBLGen Pro
Justin
User
Posts: 6
Joined: 14-Nov-2004
# Posted on: 21-Dec-2004 09:48:46   

Otis wrote:

The amount of objects to update should be limited by a filter.

Sorry for digging up this old thread but I can't get my head around how to accomplish the above. I'm trying to update x number of records of an avialable inventory. Below is my code, I didn't see anything in the reference about limiting records affected in a PredicateExpression.


ItemCollection items = new ItemCollection();
ItemEntity item = new ItemEntity();
item.Status = "Picked";
IPredicateExpression selectFilter = new PredicateExpression();
                    selectFilter.Add(PredicateFactory.CompareValue(ItemFieldIndex.ProductID, ComparisonOperator.Equal, 8));
                                selectFilter.AddWithAnd(PredicateFactory.CompareValue(ItemFieldIndex.Status, ComparisonOperator.Equal, "Available"));
int RecordsAffected = items.UpdateMulti(item, selectFilter);

There are 200 products with a ProductID of 8 and a status of "Available" but I want to set the status of 20 to "Picked".

I searched the forum already but this thread seemed to be the closest to what I am trying to do.

Thanks, Justin

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 21-Dec-2004 11:16:48   

specify a filter which selects just the 20 of them. If that's not possible (or very cumbersome) load the 20 in memory and alter it there. Those are the options you have. Specifying a filter for 200 will indeed affect all 200.

Frans Bouma | Lead developer LLBLGen Pro