I am trying to create a general method for accessing the DB. This will imply parameters like: page index, number of items to display per page, ordering options, load options etc.
...
public IQuerable<T> GetAll(int pageIndex, int itemsToDisplayPerPage, System.Linq.Expressions.Expression<Func<T,object>>[] orderBy, System.Linq.Expressions.Expression<Func<T,object>>[] loadOptions)
{
DataContext dc = null;
IQuerable<T> result = null;
// Make some initalizations
...
foreach(var item in orderBy)
{
result = result.OrderBy(item);
}
System.Data.Linq.DataLoadOptions loadOptions = new System.Data.Linq.DataLoadOptions();
foreach(var item in loadOptions)
{
loadOptions.LoadWith(item);
}
...
}
...
The problem is that the System.Linq.Expressions.Expression< Func< T,object > >
type is not a good general representation of any lambda expression that will be passed for the both examples above.
On ordering will crash because of the object type that does not make any sense for ordering. Also on loadWith will not work. So i dont know how can i handle this problem. Any suggestions? Thank you.