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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:26:47+00:00 2026-05-23T17:26:47+00:00

In my controller i am trying to use include with EF4 to select related

  • 0

In my controller i am trying to use include with EF4 to select related entities, but the lambda expression is throwing the following error,

i have the related entity defined in the Entity class like

public class CustomerSite
{
    public int CustomerSiteId { get; set; }
    public int CustomerId { get; set; }
    public virtual Customer Customer { get; set; }
}

Then in my controller i have

 var sites = context.CustomerSites.Include(c => c.Customer);

 public ViewResult List()
 {
    var sites = context.CustomerSites.Include(c => c.Customer);
    return View(sites.ToList());
 }

Can anyone kindly point me in the right direction on what i’m doing wrong here?

  • 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-23T17:26:48+00:00Added an answer on May 23, 2026 at 5:26 pm

    The Include method expects a string, not a lambda:

    public ViewResult List()
    {
        var sites = context.CustomerSites.Include("Customer");
        return View(sites.ToList());
    }
    

    Of course you could write a custom extension method which would work with lambda expressions and make your code independant of some magic strings and refactor friendlier.

    But whatever you do PLEASE OH PLEASE don’t pass EF autogenerated objects to your views. USE VIEW MODELS.

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

Sidebar

Related Questions

I'm getting the following error when trying to use a modular layout in my
I am trying to use UpdateModel in a class other than my controller and
I am trying to use a layout for each actions in a controller. For
I am trying to use some action when I click button in navigation controller.
I am trying to unit test a controller action that uses UpdateModel but I
I am trying to use the Phaxio API to include the ability to send
I am trying to use acts_as_taggable plugin to include tag functionality in my ruby
I'm trying to use WebGrid HtmlHelper to display data from a few entities. The
I'm trying to use Ajax with my CRUD. I'm following this tutorial . I
I am trying to use Gigya_Social_Network_CakePHP_Plugin. I have installed cake 1.3 and and download

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.