I have code for strongly typing. Includes () in linq, for example ...
public static ObjectQuery<T> Include<T>(this ObjectQuery<T> mainQuery, Expression<Func<T, object>> subSelector)
{
return mainQuery.Include(((subSelector.Body as MemberExpression).Member as System.Reflection.PropertyInfo).Name);
}
public static ObjectQuery<T> Include<T, Q>(this ObjectQuery<T> mainQuery, Expression<Func<T, object>> tSubSelector, Expression<Func<Q, object>> qSubSelector)
{
string tProperty = ((tSubSelector.Body as MemberExpression).Member as System.Reflection.PropertyInfo).Name;
string qProperty = ((qSubSelector.Body as MemberExpression).Member as System.Reflection.PropertyInfo).Name;
string path = string.Format("{0}.{1}", tProperty, qProperty);
return mainQuery.Include(path);
}
My question is, is there anyway I can write a more general function account for any level of sequential inclusion? Instead of rewriting it, say, 3, 4, etc. Include types?
source
share