Mladen Macanović
Mladen Macanović

Reputation: 1194

BLToolkit update with join

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
                            } );

Upvotes: 1

Views: 939

Answers (1)

IT.
IT.

Reputation: 878

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 });

Upvotes: 1

Related Questions