0

I am trying to do a nested lookup to go down N Levels using the C# MongoDb Client.

I have these Class

class User {

public string Id {get;set;}

public string Name {get;set;}

}
class Category {

public string Id {get;set;}

public string Name {get;set;}

public string UserId {get;set;}
}
class Product {

public string Id {get;set;}

public string Name {get;set;}

public string CategoryId {get;set;}

}

Now I can do a normal LookUp very easily and even N Lookups using the details provide on this Link

Here are my joined Classed for Fetching:

class UserJoined : User {
 public ICollection<Category> Categories {get;set;}
}

class CategoryJoined : Category {
 public ICollection<Product> Products {get;set;}
}

But I want to do nested.

I was thinking of this Approach by adding a new field in the User to go nested

class UserJoined : User {
 public ICollection<Category> Categories {get;set;}
 public ICollection<CategoryJoined> CategoryJoins {get;set;}
}

But I don't know the syntax to go nested in C# MongoDb.

2
  • it's not clear what your exact requirement is. if you embed/nest entities within parent entities, you'll get back all nested entities with the parent if you do a find query on the parent collection. you just need to have the matching c# classes for the driver to correctly deserialize what mongo returns. if you specify your exact querying requirement, we may be able to help. Commented Dec 11, 2020 at 3:26
  • @ĐĵΝιΓΞΗΛψΚ My requirement are to do N Level joins like in EF Core, move vertically downwards for example User has many categories and each category has many products, now lets suppose I want to fetch a user with all its categories and for each categories all its products Commented Dec 11, 2020 at 10:26

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.