Update with value in DB

Posts   
 
    
Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 29-Dec-2005 22:09:56   

Hi,

Is it possible to do something like this...


UPDATE 
    s2
SET 
    s2.quantity = s2.quantity + s1.quantity
FROM 
    ShoppingCart s1
JOIN 
    ShoppingCart s2
ON 
    s1.productID = s2.productID

...its the 's2.quantity = s2.quantity + s1.quantity' that I'm after.

Cheers, I.

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 30-Dec-2005 01:37:16   

you could do this

// C#
IExpression updateExpression = 
    new Expression(ShoppingCart.Quantity, ExOp.Mul, 2.0f);
ShoppingCartEntity shoppingcart = new ShoppingCartEntity();
shoppingcart.Fields[(int)ShoppingCartFieldIndex.Quantity].ExpressionToApply = updateExpression;
ShoppingCartCollection shoppingcarts = new ShoppingCartCollection();
// no filter is specified, all carts have their quantities doubled, but you could of course
// specify a filter to limit the scope of the update.
shoppingcarts.UpdateMulti(shoppingcart, null);

// the expression declaration can also be done like this:
ShoppingCartEntity shoppingcart = new ShoppingCartEntity();
shoppingcart.Fields[(int)ShoppingCartFieldIndex.Salary].ExpressionToApply = 
    (ShoppingCartFields.Quantity * 2.0f);

This is all ripped from the manual under the Using the entity collection classes, SelfServicing -> Updating a set of entities in the persistent storage