Lieven Cardoen
Lieven Cardoen

Reputation: 25959

SubSonic3 Update Question

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

Upvotes: 0

Views: 88

Answers (2)

davethecoder
davethecoder

Reputation: 3932

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

Upvotes: 0

Amgad Fahmi
Amgad Fahmi

Reputation: 4349

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

Upvotes: 1

Related Questions