I'm writing some BLL code to sit on top of Entity framework (DAL classes generated with DBContext but that doesn't matter for this question). Here's one of my routines:
public static Customer Get(int32 CustID, IEnumerable<string> IncludeEntities = null)
{
}
So when I call it I pass a CustID, an optinal list of Entities I want included -such as "Orders", and "OrderDetails":
Customer customer = CustomerBLLRepository.Get("ALFKI",
new[] { "Orders", "Orders.Order_Details"});
It works fine but I don't like calling it with a list or array of strings - I'd like to get strong typing so the IDE can assist.
I could receive a list of types by declaring it like this:
public static void GetTest(Int32 CustID, params Type[] IncludeEntities)
{
}
and get the class name as a string for the includes to work, but then the caller has to use typeofs like this:
CustomerRepository.GetTest(123, typeof(Order), typeof(OrderDetails));
which is not the end of the world, but this causes problems because OrderDetails is actually a navigation property from Orders, and the include needs to be called Orders.OrderDetails, and I'd have to have the code poke around to find which entity OrderDetails in the child of and still generate the string.
What I really want is a strongly typed list of entities to pass as includes in the same format EF wants them as includes but I think I am SOL.