請原諒我,如果我對你的意圖不滿意,因爲我的查詢摘錄中看不到數據的完整結構或最初的from
或最終的select
子句。所以我發佈了我認爲是基於您構建的片段和示例數據的解決方案。如果我關機,請告訴我,我會糾正它。
如果你想託運到豆莢行的列表,每一批貨到POD上自己的路線,你可以做這樣的事情(記住我from
和select
條款都是基於我的樣本數據):
// select the consignment id & name (i made up) and each matching POD
var results = from c in consignments
join p in dc.PODs on c.ID equals p.Consignment into pg
from pgg in pg.DefaultIfEmpty()
select new { ID = c.ID, Name = c.Name, POD = pgg };
// This is just a SAMPLE display just for kicks and grins
foreach (var r in results)
{
Console.WriteLine(r.Name + " " + ((r.POD != null)
? (r.POD.Consignment + " " + r.POD.Description)
: "none"));
}
這個查詢輸出是這樣的:
One 1 TextBox
Two none
Three 3 Refridgerator
Three 3 Bucket
Four none
Five none
但是我不能肯定我理解你的話:
「問題是,我得到 重複的主行」
我不知道,如果你說你不希望看到每行每購買一次託運,其中每個結果該IEnumerable
與貨物和豆莢序列中的項目,你會想要像一個查詢:
// select the Consignment ID and Name (i made up), and list of PODs
// instead of the individual POD
var results = from c in consignments
join p in dc.PODs on c.ID equals p.Consignment into pg
select new { ID = c.ID, Name = c.Name, PODs = pg };
// This is just a SAMPLE display just for kicks and grins
foreach (var r in results)
{
Console.WriteLine(r.Name + " ");
if (r.PODs.Count() > 0)
{
foreach (var pod in r.PODs)
{
Console.WriteLine("\t" + pod.Consignment + " " + pod.Description);
}
}
else
{
Console.WriteLine("\tNone");
}
}
凡選擇是選擇POD列表,而不是個人的比賽,它輸出這樣的:
One
1 TextBox
Two
None
Three
3 Refridgerator
3 Bucket
Four
None
Five
None
可以顯示完整的查詢。 – msarchet
對不起,目前我不能上網,因爲我在沒有互聯網接入的機器上工作。當我有5分鐘時間,我會輸入它:) – Chris
工作沒有互聯網接入?不會管理第二個 –