I have a Generic list say List<TransactionInfo>
TransactionInfo class have three properties:-
public long TransactionId { get; set; }
public string BuyerName { get; set; }
public string SellerName { get; set; }
If below is data in my list:-
1 A B
2 A C
3 A D
4 G H
5 C M
6 D E
7 A F
8 H L
9 L R
10 Y Z
Then I want to create group clusters based on the transactions between members. I want to write LINQ query that should return new List
ClusterInfo Class contains one property:-
public List<TransactionInfo> Transactions { get; set; }
List<ClusterInfo> should contain:-
clusters[0]:-
1 A B
2 A C
3 A D
5 C M
6 D E
7 A F
clusters[1]
4 G H
8 H L
9 L R
clusters[2]
10 Y Z
How these new lists are selected:-
All the direct or indirect Buyers/Sellers should be part of one cluster.
Can anyone help me in writing LINQ query to achieve this. If not LINQ then simple for loop solution will also suffice.
PS :- posting this from mobile.. so plz excuse bad formatting
Here is the solution:
With the class:
And, the class that find the connected components: