Hi!
I have a window that shows customer infomation.
when the window loads, I call LoadCustomer()
method from the constructor which loads the customer information from the database asynchorously, which sets the CurrentCustomer
property.
and then the UI is updated because it is bound to the CurrentCustomer
.
private void LoadCustomer(Guid customerID)
{
CustomerContext customerContext = new CustomerContext();
var customerQuery = customerContext.GetCustomersQuery()
.Where(e => e.CustomerID == customerID);
customerContext.Load(customerQuery, loadOperation =>
{
CurrentCustomer = loadOperation.Entities.SingleOrDefault();
}, null);
}
The senior programmer has told me that it's better to put this logic inside CurrentCustomer's get accessor, because then 1. the calls to the database will use lazy loading, and 2. the refactoring would be easier.
Is it good practice to put async database calls inside property's get accessor?