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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:34:11+00:00 2026-06-15T17:34:11+00:00

I am trying to create a multiple include method in my repository to use

  • 0

I am trying to create a multiple include method in my repository to use as follows:

repository.Include<Post>(x => x.Images, x => x.Tags).First(x => x.Id == 1)

I tried something as:

public IQueryable<T> Include<T>(params Expression<Func<T, Object>>[] paths) where T : class {
  return paths.Aggregate(_context.Set<T>(), (x, path) => x.Include(path));
} // Include

But I get the error:

Cannot implicitly convert type ‘System.Linq.IQueryable’ to ‘System.Data.Entity.DbSet’.

Note that the original include is the following:

public static IQueryable Include(
this IQueryable source,
Expression> path
) where T : class;

Can I make this work without turning my repository method into static?

Thank You,

Miguel

  • 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-15T17:34:11+00:00Added an answer on June 15, 2026 at 5:34 pm

    If you really want to create your own .Include non-extension method that allows for multiple paths in one call, internally translating to the already provided .Include method, you can do something like

    public IQueryable<T> Include<T>(params Expression<Func<T, object>>[] paths)
        where T : class
    {
        IQueryable<T> query = _context.Set<T>();
        foreach (var path in paths)
            query = query.Include(path);
        return query;
    }
    

    This is pretty close to what you have already, but avoids the pitfall with Enumerable.Aggregate that you encountered: you’d have the same problem if you replace IQueryable<T> query with var query in my version.

    Note that using many .Include may harm performance. If it does in your situation, you can rewrite it to use multiple queries, which you can run one after the other in a transaction.

    Personally, as you can call the already provided .Include extension method (using System.Data.Entity;) on any IQueryable, I’d just write it as:

    repository.Posts.Include(x => x.Images).Include(x => x.Tags).First(x => x.Id == 1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a method that accepts multiple types of controls -
I am trying to use NAudio to create a multiple sound output application. We
I'm trying to create multiple sheets by iteration in phpexcel: $i=0; while ($i <
I am trying to create a multiple image uploader and I have come across
I'm trying to create a target which matches multiple directories, but no files. Is
I'm trying to create an app that multiple users would log into a server
I am trying to create a sequenced SCORM 1.2 package with multiple modules in
I am trying to create a universal image selector for multiple buttons. Is there
I am trying to create a series of tables with multiple foreign key relationships.
I am trying to create an android app which will show multiple web urls

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.