Update TableToBeUpdated
Set ColumnNameId = (Select MasterColumnId
from MasterTable where Id = @Id)
Where ForeingKeyId = @Id
AND AnotherColumn = @AnotherColumn
How to achieve the above with one select statement and an update statement with a subquery?
Currently what I'm thinking is.
//First Select statement
var tableTBU = (from t in MsDataContext.TableToBeUpdated
where t.ForeingKeyId == <valueFromVariable>
select t ).SingleOrDefault();
//Second select statement
var masterIdValue = (from m in MsDataContext.MasterTable
where m.Id == <valueFromVariable>
select mod.MasterColumnId ).SingleOrDefault();
tableTBU.ColumnNameId = masterIdValue ;
tableTBU.SomeOtherColumn = "dkjsdlfs";
//Some more things to be updated.
//UpdateStatement
MsDataContext.SubmitChanges();