ObjectTransactionGetTObject Method |
Namespace: Aloe.SystemFrameworks.Domain
Get first searches the local cache for the object. If the object is not found, it is loaded from the data source. When the object is not found locally, a reference is returned, which is only initialized with the specified id. No data is loaded from the database initially. Data attributes and object references are lazy loaded upon first reference. Example:
//this will get a reference to a Customer object, but it will not "touch" the database Customer c = tran.Get<Customer>(custId); //this will load the customer Console.WriteLine(c.IsActive);
Lazy loading also ensures, that everything is loaded as lazy as possible. Check this example:
//The SalesOrder object is not loaded, just lazy initialized SalesOrder so = tran.Get<SalesOrder>(salesOrderId); //The SalesOrder is loaded and a new lazy Customer object is initialized Customer c = so.Customer; //Nothing is allocated. Accessing the .Id property does not trigger lazy self loader Guid custId = so.Customer.Id; //Now the customer object is loaded also string name = so.Customer.Name;