我需要存储此类的一些对象:
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;}
}
当我使用 NoRM 并使用 mongo.GetCollection().Insert(Category); 存储类别对象时 我可以在 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" : {
}
}
] }
我可以将 Category 和 Product 对象存储在不同的集合中,并且只引用 Category 记录中的 Product 而无需更改类的代码吗?(就像 NHibernate 一样)