我试图创建一个简单的引用,但我没有得到它。 A"客户"集合创建成功,但" ordes"集合未创建。
此代码有什么问题?
public static void Main()
{
var mapper = BsonMapper.Global;
mapper.Entity<Customer>()
.DbRef(x => x.Order, "orders");
using (var db = new LiteDatabase(@"MyData.db", mapper))
{
var col = db.GetCollection<Customer>("customers");
var customer = new Customer
{
Id = 1,
Name = "John Doe",
Phones = new string[] { "8000-0000", "9000-0000" },
Age = 39,
IsActive = true,
Order = new Order { Id = 1, Name = "My first order" }
};
col.Insert(customer);
}
}
答案 0 :(得分:1)
您必须获得Order集合的引用,在Order集合中插入订单。您的代码假定这将是级联插入。