我有一些类似这样的代码:
var customer = dbcontext.Customers.Find(1);
var order = new Order();
order.CustomerId = customer.Id;
dbcontext.Orders.Add(order);
dbcontext.SaveChanges();
在设置导航属性时,是最佳实践是这样做还是通过设置关系来进行设置?
var customer = dbcontext.Customers.Find(1);
var order = new Order();
order.Customer = customer; //Set navigation prop as opposed to FK field
dbcontext.Orders.Add(order);
dbcontext.SaveChanges();
哪种方法被认为是最佳实践或首选方法?