我一直在試圖開發一個linq查詢,它返回數據庫中所有表的ItemNumber列,但到目前爲止我還沒有能夠成功完成。Linq到SQl,從多個表中選擇相同的列
基本上我有一個計算機中每種硬件組件的表,每個表都有一個ItemNumber列。我需要在一個bang中查詢所有表,然後返回一個扁平列表/數組中的ItemNumber值。 (基本上我希望能夠做到以下)
foreach (var c in items) {
Console.WriteLine(c.ItemNumber);
}
搜索網無濟於事,可能有人告訴我如何做到這一點的例子嗎?我最好的嘗試如下,但我不明白Sql足以實現這一點。
var items = from hc in dc.DataBoxPCHardwareCases
from hhd in dc.DataBoxPCHardwareHardDrives
from hkb in dc.DataBoxPCHardwareKeyboards
from hmm in dc.DataBoxPCHardwareMemories
from hmo in dc.DataBoxPCHardwareMonitors
from hmb in dc.DataBoxPCHardwareMotherboards
from hms in dc.DataBoxPCHardwareMouses
from hod in dc.DataBoxPCHardwareOpticalDrives
from hps in dc.DataBoxPCHardwarePowerSupplies
from hpc in dc.DataBoxPCHardwareProcessors
from hsp in dc.DataBoxPCHardwareSpeakers
from hvc in dc.DataBoxPCHardwareVideoCards
from sos in dc.DataBoxPCSoftwareOperatingSystems
select new { hc, hhd, hkb, hmm, hmo, hmb, hms, hod, hps, hpc, hsp, hvc, sos };
我剛編輯了代碼佈局,使其更易於閱讀。希望你不介意。 – 2009-01-26 23:19:37
我想我意外地解開了! – 2009-01-26 23:20:47