我需要存储一些这些类的对象:
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)存储一个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" : {
}
}
] }
我可以将类别和产品对象存储在不同的集合中,并且只在类别记录中引用产品而不更改类的代码吗?(就像NHibernate一样)