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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:09:53+00:00 2026-05-25T15:09:53+00:00

This is not making any sense. The query i’m running is shown below. The

  • 0

This is not making any sense. The query i’m running is shown below. The result of the query is data-bound to a form.

    public Message GetMessage(Guid authorizationKey)
    {
        using (MyEntities context = new MyEntities())
        {
            var result = (from message in context.Messages
                              .Include("Attachments")
                              .Include("Authentication")
                          join authentication in context.Authentications on message.Authentication.AuthenticationId equals authentication.AuthenticationId
                          where authentication.AuthorizationKey == authorizationKey
                          select message).FirstOrDefault();

            return result;
        }
    }

The weird shit: If i put a break-point, step through the query and data-bind everything works. Soon as i remove the breakpoint my Authentication nav property isn’t loaded. Can somebody shed some light on why this is occurring?

  • 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-25T15:09:54+00:00Added an answer on May 25, 2026 at 3:09 pm

    Include and Select do not work together.

    You are telling the DataContext to return the message variable that only contains the message (even though you have the include statements on the context.Messages object). Two ways to fix this would be:

    1) Project message, Attachments, Authentication into a POCO object in your select statement

            var result = (from message in context.Messages 
                              .Include("Attachments") 
                              .Include("Authentication") 
                          join authentication in context.Authentications on message.Authentication.AuthenticationId equals authentication.AuthenticationId 
                          where authentication.AuthorizationKey == authorizationKey 
                          select new MessageWithNavigations()
    {
    Message = message,
    Authentication = message.Authentication,
    Attachments = message.Attachments,
    }).FirstOrDefault(); 
    
            return result; 
    

    2) Use the fluent notation across the whole queryable

    var result = context.Messages
        .Include("Attachments")
        .Include("Authentication")
        .Where(m => m.Authentication.AuthorizationKey == authorizationKey)
        .FirstOrDefault();
    

    The problem with #1 is that you will not be able to do anything with the instances of the object that would fire a query off (like a navigation), or edit any properties on those objects. Projection only gives you essentially read-only objects.

    With #2, it might be better to use .SingleOrDefault instead of FirstOrDefault if your AuthorizationKey is a unique value / primary key.

    The gist of the problem is that using include with select in the same IQueryable object essentially confuses the query builder expression tree and it chooses to ignore your include statements.

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

Sidebar

Related Questions

I'm getting a build error in Visual Studio that's not making any sense: The
trying to do something pretty obvious really but its kinda not making any sense
I am having difficulty making any sense of this! What is he trying to
I'm not talking about making portable code. This is more a question of distribution.
This is weird and probably not possible but I'll ask anyway. I'm making this
I am not overly competent in C++ and this compiler error is just making
I'm making a new Mac OS X application. (not an iPhone app) This is
Why does this not work? Do I not understand delegate covariance correctly? public delegate
So I'm making this android application, that needs to read data from user-provided CSV
Exception Thrown: System.ComponentModel.ReflectPropertyDescriptor is not marked as Serializable Does this mean I missed marking

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.