sqlkata / querybuilder

SQL query builder, written in c#, helps you build complex queries easily, supports SqlServer, MySql, PostgreSql, Oracle, Sqlite and Firebird
https://sqlkata.com
MIT License
3.11k stars 500 forks source link

Update with Joins #637

Open SeanLawless opened 1 year ago

SeanLawless commented 1 year ago

Hi,

Just wondering if it is possible to build a query statement to update a table which includes joins. When using the Update() method it compiles fine but does not include the joins in the compiled query. Example below :

Query("Table1").Join("Table2", "Table2.Column1", "Table1.Column2").Where("Table2.Column3", 1).Update(new {Column5= 1})

Using the compiler this will compile to the blow :

UPDATE [Table1] SET [Column5] = 1 WHERE [Table2].[Column3] = 1

There is no error shown on compilation but it just ignores the joined table completely when run. Can you please advise on a fix for this? From reading the code version one would expect to see the join in the compiled query.

This should be compiling to the following :

UPDATE [Table1] SET [Column5] = 1 FROM [Table1] JOIN [Table2] ON [Table2].[Column1] = [Table1].[Column2] WHERE [Table2].[Column3] = 1

TIA.