Rakesh reddy

Rakesh reddy

  • NA
  • 201
  • 5.5k

How to find the parent list using Linq Query for below

Jun 13 2018 1:41 AM
   
I Have classes
public class User
{
Int UserId;
String UserName
products List
}
 
public class Product
{
int ProductId;
int ProductName;
}
 
var data = new List();
 
data.Add(1, new List { new Product {prdouctId= 1, ProductName = "Name1"} , new Product {ProductId=2, ProductName="Name2"}}
 
data.Add(2, new List { new Product {prdouctId= 2, ProductName = "Name2"} , new Product {ProductId=3, ProductName="Name3"}}
 
data.Add(3, new List { new Product {prdouctId= 4, ProductName = "Name4"} , new Product {ProductId=2, ProductName="Name1"}} 
 
How we get the users List with Linq query who are mapped product wise
 
Expected Result:
---------------------- 
ProdcutId     UsersId
1                  {1,3}
2                  {1,2,3}
3                 {2,3}

Answers (3)