1

In EF7 there is a new ExecuteUpdate function to do updates on a table without retrieving the data from the server first. Is it possible to do an update from select with this method in any way where it is using data from another table? To be more concrete can i express this SQL in EF:

UPDATE
    Table_A
SET
    Table_A.col1 = Table_B.col1,
    Table_A.col2 = Table_B.col2
FROM
    Some_Table AS Table_A
    INNER JOIN Other_Table AS Table_B
        ON Table_A.id = Table_B.id
WHERE
    Table_A.col3 = 'cool'
HrkBrkkl
  • 613
  • 5
  • 22

1 Answers1

4

The following query updates table with values from joined table.

var query = 
    from a in context.TableA
    join b in context.TableB on a.id equals b.id
    where a.col3 == "cool"
    select new { a, b };

query.ExecuteUpdate(s => 
    s.SetProperty(x => x.a.col1, x => x.b.col1)
     .SetProperty(x => x.a.col2, x => x.b.col2)
);
Svyatoslav Danyliv
  • 21,911
  • 3
  • 16
  • 32