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 8719495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:48:45+00:00 2026-06-13T06:48:45+00:00

In EF, when you want to include a navigation property in the result of

  • 0

In EF, when you want to include a navigation property in the result of a query, you use Include(). Since some queries require calling this more than once, I tried to create a generic wrapper around this concept:

public IQueryable<T> FindAll<P>(params Expression<Func<T, P>>[] predicates) where P : class {
  var entities = AllEntities();
  foreach (var p in predicates) entities = entities.Include(p);
  return entities;
}

And call it as such:

var customers = FindAll(q => q.Orders, q => q.Invoices, q => q.Contacts);

Questions:

  1. The function compiles, but when I call it: “The type arguments for method cannot be inferred from the usage. Try specifying the type arguments explicitly.” What am I doing wrong?
  2. If I get it to work, can I call Include() the first time: var customers = FindAll(q => q.Orders, q => q.Invoices); and then again later in a separate step: customers = customers.Include(p => p.Invoices); or will that result in poor performance such that I should do the includes in one go?

EDIT:
JonSkeet’s answer is correct, of course, and yet there is this solution which seems to do what I want. Not sure why it works however. Is it because of the Aggregate() function?

  • 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-06-13T06:48:46+00:00Added an answer on June 13, 2026 at 6:48 am

    Fundamentally, I think you’ve got a problem – assuming that q.Orders, q.Invoices and q.Contacts return different types, you can’t express what you want to happen. You probably want something like:

    entities.Include<Parent, Order>(p => p.Order);
    entities.Include<Parent, Invoice>(p => p.Invoices);
    entities.Include<Parent, Contact>(p => p.Contacts);
    

    … so you want a different value for P for each predicate. But you’re calling a single method, providing a single type argument for P.

    It’s not clear that this is really giving you much benefit anyway… couldn’t you just write:

    var customers = AllEntities().Include(q => q.Orders)
                                 .Include(q => q.Invoices)
                                 .Include(q => q.Contacts);
    

    I’d say that’s clearer and it gets round the “multiple type parameters” problem.

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

Sidebar

Related Questions

I want to include an admob banner in my application and I got this
I want to include jQuery UI in my jsp page. I tried this <jsp:root
The problem: I want to use PHP include to import file header_menu.html into all
I want to include the same navigation menu on multiple pages, however I do
I have a query below, but I want to perform an Include() to eager
Using this function I want to create a PHP navigation: function loadPage($pagename) { if
If I want to include navigation propeties of two levels, it it enough to
I want include the Type name of each object in my collection from my
I want to include a php file in a div box whenever one generated
I want to include the chosen library like my other js libraries in my

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.