Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7520891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:08:44+00:00 2026-05-30T02:08:44+00:00

Is something like the following construct possible? public IQueryable<T> AllWithFetch<TRelated>(IQueryable<T> existing, params Expression<Func<T, TRelated>>[]

  • 0

Is something like the following construct possible?

  public IQueryable<T> AllWithFetch<TRelated>(IQueryable<T> existing, params Expression<Func<T, TRelated>>[] fetchExpressions)
  {
     return fetchExpressions.Aggregate(existing, (current, exp) => current.Fetch(exp));
  }

Which could then be called like this…

var allDetails = this.preGrantDetailRepository
                .AllWithFetch(this.preGrantDetailRepository.All, x => x.Case, x => x.CaseOwner)

Basically I am trying to include the addition of fetching strategies for NHibernate to our abstract repository, to enable us to specify these strategies from our logic layer without breaking the repository pattern. For example if we changed from NHibernate to another ORM we can then provide the same repository methods but implemented for that ORM.

The problem appears when I try to chain on more than one func in the param array.

So this works…

var allDetails = this.preGrantDetailRepository
                .AllWithFetch(this.preGrantDetailRepository.All, x => x.Case)

But this fails with “the type arguments cannot be inferred from their usage” messge

var allDetails = this.preGrantDetailRepository
                .AllWithFetch(this.preGrantDetailRepository.All, x => x.Case, x => x.CaseOwner)

I’m using .NET 3.5, Repository Pattern, Fluent NHibernate, SQL Server 2008

EDIT

I solved the problem in the with help from Porges answers below, so I have acepted it. The problem did come from an incorrect 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));
        }

It is now AllWithFetch not TRelated and I am using the super class of the two entities (Case & CaseOwner) in the Func.

Thank you for your help guys

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T02:08:44+00:00Added an answer on May 30, 2026 at 2:08 am

    The problem is your TRelated, this isn’t anything to do with params specifically.

    Try this, for example:

    void DoSomething<T,U>(Func<T,U> f, Func<T,U> f2)
    {
    }
    
    void Main()
    {
        DoSomething((int x) => x + 1, (int x) => x + ""); 
    }
    

    The compiler will infer that T must be int, but it cannot infer a good type for U (I’m not sure of the exact details, but it generally won’t look for a type higher up the inheritance chain).

    To get it to work, you need to specify the superclass; in this case, object:

    void Main()
    {
        DoSomething<int,object>((int x) => x + 1, (int x) => x + ""); 
    }
    

    So you’ll either need to specify a superclass yourself (which looks like it will be object here), or just get rid of the TRelated parameter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want something like the following: foo.should_receive(:bar).with(an_instance_of(Bla))..... Is this possible? Edit: According to the
I want to write something like the following: internal class InternalData { } public
Why something like following is not allowed. I mean why the following method will
I want something like the following but would like it to be reusable for
I'm doing something like the following: Validate number of nested attributes . I'm checking
I have something like the following data structure: Category StartDateTime EndDateTime =============================================== 1 12/1/2009
Suppose I have something like the following in test.cxx (and that I do the
I'm attempting something like the following: switch ($p) { foreach ($modules as $m) {
Is there something like the following in Apache Common Lang or Spring Utils or
So I have something like the following in Java: private List<SomeType>variable; // ....variable is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.