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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:25:41+00:00 2026-05-31T20:25:41+00:00

I just declared some code-first models for a new project that uses EntityFramework. public

  • 0

I just declared some code-first models for a new project that uses EntityFramework.

public class BlogEntry
{
    public long Id { get; set; }
    public long AuthorId { get; set; }
    public DateTime PublishedStamp { get; set; }
    public string Title { get; set; }
    public string Text { get; set; }

    public virtual User Author { get; set; }
}

public class User
{
    public long Id { get; set; }
    public string Email { get; set; }
    // ...
}

class BlogDb : DbContext
{
    public DbSet<BlogEntry> Entries { get; set; }
    public DbSet<User> Users { get; set; }
}

Now suppose I want to retrieve the 10 most recent blog entries:

var entries = new BlogDb().Entries.OrderByDescending(...).Take(10).ToList();

The problem now is that accessing entry.Author will cause another database query. You wouldn’t want a separate such query for every blog entry. Now, it is my understanding that the purpose of Include is exactly this case, so I can say:

var entries = new BlogDb().Entries.Include(e => e.Author).(...).ToList();

However, that method doesn’t seem to exist. There is only an Include(string), like this:

var entries = new BlogDb().Entries.Include("Author").(...).ToList();

but this is annoying because it’s not compile-time checked and will be missed by the rename refactoring. Surely the version with the lambda is the “correct” approach.

Where did that method go? Is it no longer included in EntityFramework?

(I know that I can write an extension method for myself to achieve this, so you don’t have to. I’d just like to know whether I’m missing something.)

  • 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-31T20:25:43+00:00Added an answer on May 31, 2026 at 8:25 pm
    using System.Data.Entity;
    

    It’s in EF v4.1 and above, but you need a reference as it is an extension method.


    Edit (thanks to @EastonJamesHarvey)

    If using EF Core the import should be:

    using Microsoft.EntityFrameworkCore;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just noticed in ByteArrayOutputStream , the toByteArray() is declared as, public synchronized byte toByteArray()[];
Just looking for the first step basic solution here that keeps the honest people
I just discovered that the following code executes without error (Chrome): console.log(fa); function fa(){}
I had to change some code that was created by another person in VS2008,
I am working on some legacy code and have come across something that I'm
I'm working on some code that generates a lot of ignoring return value of
I am trying to write a program to check that some C source code
First of all, there are many questions just like this, and perhaps some OPs
I have some C++ code, in which the following enum is declared: enum Some
I have some code that does the following: while(some condition) { char *line[WORDLEN]; //do

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.