0
Update TableToBeUpdated
Set ColumnNameId = (Select MasterColumnId
from MasterTable where Id = @Id)
Where ForeingKeyId = @Id
AND AnotherColumn = @AnotherColumn
如何與一個select語句和使用子查詢的更新語句實現上述的?更新與Linq中選擇查詢值到SQL
目前我在想什麼。
//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();
我想我把問題複雜化了,因爲這樣你就感到困惑。如果您只是將T-SQL語句轉換爲LINQ,那將會很棒。我沒有指定任何外鍵或在設計器上完成任何手動映射。實際上MasterTable和TableToBeUpdated還有一對多的關係。 – IsmailS 2010-10-13 05:21:30