I have a repository with the following method:
IEnumerable<T> FindAll<TRelated>(Specification<T> specification,
Expression<Func<T, TRelated>> fetchExpression);
I need to pass in more than one expression. I was thinking about changing the signature to:
IEnumerable<T> FindAll<TRelated>(Specification<T> specification,
IEnumerable<Expression<Func<T, TRelated>>> fetchExpression);
- Is this possible?
- How do I create an array, say, of expressions to pass into this method?
Currently I'm calling the method from my service layer like this:
var products = productRepository.FindAll(specification,p => p.Variants);
But I'd like to pass p => p.Variants
and p => p.Reviews
for example. And then in the repository I'd like to iterate through the expression and add them to a query.
For a bit of background on why I am doing this see Ben Foster's blog post on Eager loading with NHibernate.