tags:

views:

56

answers:

2

Is it possible to do something like this in SubSonic3?

_db.Update<Product>()
    .Set("UnitPrice")
    .EqualTo(UnitPrice + 5)
    .Where<Product>(x=>x.ProductID==5)
    .Execute();

I would need something lik this:

UPDATE      Blocks
SET         OrderId = OrderId - 1
WHERE       ComponentId = 3

But in SubSonic3

+1  A: 

I think you can here is a sample for demonstrating how you can use subsonic 3

// One thing you might not have seen with Linq To Sql is the ability to run Updates //and Inserts, which I've always missed and have now implemented with SubSonic 3.0:

            db.Update<Products>().Set(
                x => x.Discontinued == false, 
                x => x.ReorderLevel == 100)
               .Where(x=>x.Category==5)
               .Execute();

        db.Insert.Into<Region>(x => x.RegionID, x => x.RegionDescription)
          .Values(6, "Hawaii")
          .Execute();

and here a link to the full demonstration

Amgad Fahmi
TiTaN, this isn't really doing what I want. I want to set a value that is equal to the current value -1 for instance. In your example, you're just setting all records to false and 100...
Lieven Cardoen
_db.Update<Product>() .Set( x => x.UnitPrice == x.UnitPrice + 5) .Where<Product>(x=>x.ProductID==5) .Execute();
Amgad Fahmi
Nope, doesn't work. Set doesn't accept a Lambda expression.
Lieven Cardoen
can you show me the statement you are trying to excute ?
Amgad Fahmi
A: 

i do it as a select

var model = ClassName.SingleOrDefault(x => x.id == 1);

model.name = "new name";
model.tel = " new telephone;

model.save();

done

minus4