List listDataClient;
My class DataCLient:
Client client; List<String> phoneNumber;
i have a second list
List<DataPhoneNumber> listPhoneNumber;
Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
My class DataPhoneNumber:
String phoneNumber; List<Client> client;
In my code i put data in my first list but now i want to reverse my list in the second. In the first list i have a Client wiht x NumberPhone now i want to have NumberPhone for x Client
Something like this:
var nested = categories.GroupBy(c => c.ParentId) .Select(cat => new Category { ParentId = cat.Key, Categories = cat.Select(x => new Category { Id = x.Id }).ToList() });
I did something similar and works but with two levels, if you need something more generic and with multiple levels I'm not sure if you can do it with LINQ at least.
HTH
多対多の関係をモデル化しようとしているようです。
1 つのアプローチは、この関係を明示的に表すクラスを作成することPhoneNumberAssociationです。例えば
PhoneNumberAssociation
public class PhoneNumberAssociation { private final Set<Client> clients; private final Set<String> phoneNumbers; public void addClient(Client client) { this.clients.add(client); } public void addPhoneNumber(String phoneNumber) { this.phoneNumbers.add(phoneNumber); } }
私はこのアプローチを好む傾向がありますが、関係において明確な親または子の役割がない場合です。また、リストを複数のオブジェクトに埋め込み、電話番号がクライアントに追加/削除されているかどうかに基づいて (または逆に、クライアントが電話番号に追加/削除されている場合) 追加/削除する呼び出しを連鎖させるよりも簡単です。 )。