0

我正在尝试创建一个简单的参考,但我没有得到它。成功创建了“customers”集合,但未创建“orders”集合。

这段代码有什么问题?

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);
            }
}
4

1 回答 1

1

您必须获取对 Order 集合的引用,将订单插入 Order 集合中。您的代码假定这将是级联插入。

于 2017-08-04T03:30:45.963 回答