0
我試圖從List或另一個類似的Find方法中使用Find方法。我有兩個實體和一個關聯實體,它們具有來自每個獨立實體的ID和屬性。我想在關聯列表中找到對象,但是要從兩個實體ID中找到組合......就像這樣。通過2個ID從關聯列表中獲取實體
//Entity1 attributes int ID, string NAME
List<Entity1> listEntity1 = new List<Entity1>();
listEntity1.Add(new Entity1(1, "A"));
listEntity1.Add(new Entity1(2, "B"));
listEntity1.Add(new Entity1(3, "C"));
listEntity1.Add(new Entity1(4, "D"));
listEntity1.Add(new Entity1(5, "E"));
listEntity1.Add(new Entity1(6, "F"));
//Entity2 attributes int ID, string NAME
List<Entity2> listEntity2 = new List<Entity2>();
listEntity2.Add(new Entity2(101, "AA"));
listEntity2.Add(new Entity2(102, "BB"));
listEntity2.Add(new Entity2(103, "CC"));
listEntity2.Add(new Entity2(104, "DD"));
listEntity2.Add(new Entity2(105, "EE"));
listEntity2.Add(new Entity2(106, "FF"));
//Entity1_2 attributes int ID from Entity1, int ID from Entity2
List<Entity1_2> listIntermediate = new List<Entity1_2>();
listIntermediate.Add(new Entity1_2(1, 101));
listIntermediate.Add(new Entity1_2(1, 103));
listIntermediate.Add(new Entity1_2(2, 103));
listIntermediate.Add(new Entity1_2(4, 101));
listIntermediate.Add(new Entity1_2(4, 106));
listIntermediate.Add(new Entity1_2(5, 106));
Account
Entity1_2 entity1_2 = listIntermediate.Find(by ID1 and ID2) and get the object Entity1_2 that has the info from both Entities
謝謝。
非常感謝您的回答。 –