我正在尝试使用 List 中的 Find 方法或我想做的其他类似方法。我有 2 个实体和一个关联实体,它具有来自每个独立实体的 ID 和属性。我想在关联列表中找到对象,但是对于两个实体 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
谢谢你。