Is the following construction possible?
public IQueryable<T> AllWithFetch<TRelated>(IQueryable<T> existing, params Expression<Func<T, TRelated>>[] fetchExpressions) { return fetchExpressions.Aggregate(existing, (current, exp) => current.Fetch(exp)); }
What then could be called so ...
var allDetails = this.preGrantDetailRepository .AllWithFetch(this.preGrantDetailRepository.All, x => x.Case, x => x.CaseOwner)
Basically, I am trying to include adding selection strategies for NHibernate to our abstract repository so that we can specify these strategies from our logical level without breaking the repository pattern. For example, if we changed from NHibernate to another ORM, we can provide the same repository methods, but implemented ORM for this.
The problem occurs when I try to connect to several functions in a param array.
So it works ...
var allDetails = this.preGrantDetailRepository .AllWithFetch(this.preGrantDetailRepository.All, x => x.Case)
But this fails: "type arguments cannot be deduced from their use" messge
var allDetails = this.preGrantDetailRepository .AllWithFetch(this.preGrantDetailRepository.All, x => x.Case, x => x.CaseOwner)
I am using .NET 3.5, repository template, Fluent NHibernate, SQL Server 2008
EDIT
I solved the problem using the Porges answers below, so I understood it. The problem was caused by improper use of TRelated. Here is the working method in the repository ...
public IQueryable<T> AllWithFetch<T>(IQueryable<T> existing, params Expression<Func<T, Entity>>[] fetchExpressions) { return fetchExpressions.Aggregate(existing, (current, exp) => current.Fetch(exp)); }
Now AllWithFetch is not TRelated, and I'm using the superclass of two objects (Case and CaseOwner) in Func.
Thanks for helping the guys