我一直在试图开发一个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