I have a method GetOrder(int OrderID) that runs a LINQ query and returns an order. There are many object properties that could be preloaded (i.e. with Include() ) in the query, e.g. DeliveryMethod, Customer, CustomerBillingAddress etc. I want the method to allow the caller to specify which properties are preloaded, through arguments on the method. Needless to say I don’t want to explictly write out every possible LINQ query within the method.
So is it possible to code the main query, then add .Includes dynamically, e.g.
if(PreLoadCustomer)
query.Include("Customer")
Note: I know there is lazy loading – this would not work – the related objects need to be available immediately.
Thanks
Actually it would make more sense to add the Includes first, then write the query itself: