內名單我有兩個對象模型,看起來像這樣:越來越嵌套模式
public class MyObject
{
public List<SomeOtherObject> TheListOfSomeOtherObjects { get; set; }
}
public class SomeOtherObject
{
long SomeOtherObjectID { get; set; }
}
而且我有一個名爲ListOfMyObjects
的MyObjects
一個列表,從中我想提取所有SomeOtherObjectID
是裏面列出TheListOfSomeOtherObjects
我想寫的東西是這樣的:
var ListOfAllSomeOtherObjectID = (from l in ListOfMyObjects
select l.SomeOtherObject.SomeOtherObjectID).ToList();
它的工作不是因爲Ø語法。我如何獲得嵌套列表的列表?
感謝您的建議。
其實,我想要所有孩子的SomeOtherObjectID。我試過(o => 0.ChildObject.SomeOtherObjectID),但它不接受它。 – frenchie
好的,明白了,謝謝你的回答;現在我知道了SelectMany是如何工作的!謝謝。 – frenchie