I need to store some objects of this classes:
public class Category{
public ObjectId Id {get;set;}
public string Name {get;set;}
public string Description {get;set;}
public List<Product> Products {get;set;}
}
public class Product{
public ObjectId Id {get;set;}
public string Name {get;set;}
public string Description {get;set;}
public decimal Price {get;set;}
}
When I use NoRM and store a Category object with mongo.GetCollection().Insert(Category); I can see in mongo shell:
db.Category.find()
{ "_id" : ObjectId("82bbbf0179eae0141d020000"), "Name" : "Test products", "Descr
iption" : "This is test category", "Products" : [
{
"_id" : ObjectId("81bbbf0179eae0141d000000"),
"Name" : "Product1",
"Description" : "first product",
"Price" : {
}
},
{
"_id" : ObjectId("82bbbf0179eae0141d010000"),
"Name" : "Product2",
"Description" : "second product",
"Price" : {
}
}
] }
Can I store Category and Product objects in different collections and have just a reference to a Product within a Category record without changing the code of classes? (The way like NHibernate does)