0

I'm trying to create a simple reference, but I'm not getting it. A "customers" collection is created successfully, but the "ordes" collection is not created.

What is wrong with this code?

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

1 Answers1

1

You have to get a reference to the Order collection, insert the order in the Order collection. Your code assumes that this will be a cascading insert.

fixitchris
  • 90
  • 7