1

Anyone know how can I write the following update code by using the BLToolkit syntax, where I need to join two tables, and update one of them. In SQL Server this is done like this:

update Table1 set
    Col1 = T.Col1 - TT.Col2
from
    @tempTable as TT
    inner join Table1 as T on **T.ColX = TT.ColX and T.ColY = TT.ColY**

This is how I have done the updates so far.

 db.SomeTable.Where( x => x.ColName == someColName )
                            .Update( x => new SomeTable
                            {
                                //update columns here
                            } );
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Mladen Macanović
  • 1,099
  • 7
  • 17
  • Mali savjet, trebao bi prihvatiti odgovore na prethodna pitanja koja si postavio vezana za BLT. Sto se tice ovog pitanja, nazalost ne znam, ali vec ce se neko javiti. Pozdrav :) – Marko Jul 17 '11 at 18:06
  • Hvala, tek san sad vidija da postoji accept botun. pozz :) – Mladen Macanović Jul 18 '11 at 10:05

1 Answers1

1

Example from BLToolkit unit tests:

var q =
    from c in db.Child
    join p in db.Parent on c.ParentID equals p.ParentID
    where c.ChildID == id && c.Parent.Value1 == 1
    select new { c, p };

q.Update(db.Child, _ => new Child { ChildID = _.c.ChildID + 1, ParentID = _.p.ParentID });
IT.
  • 859
  • 4
  • 11