What\'s the difference between Get
and Load
? The documentation pretty much reads the same. Also, if it matter
Load is the optimized way in some cases. Let's think of a Customer, Order relationship and assume that we have an Orders table with CustomerId as the foreign key.
var order = new Order {OrderDate = Datetime.Now };
order.Customer = session.Get(customerId);
session.Save(order);
Although we only need the customerId to persist the order object, above code block will first select the customer with that customerId from Customers table then hit the database again to insert the order for that customer.
But if we used :
order.Customer = session.Load(customerId);
only the insert statement with that customerId will be executed. Load is the appropriate way in this case.