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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:18:27+00:00 2026-05-31T22:18:27+00:00

Could anyone help me in assessing why the code below doesn’t work. I’m using

  • 0

Could anyone help me in assessing why the code below doesn’t work. I’m using the common extension method for implementing Include when using IObjectset. In our repositories we were seeing this not returning correctly so I’ve isolated the code in test app as below. I’ve also included the interface based Context if this may prove relevant and a screenshot of the relevant model section. This occurs for all Includes on IObjectSet properties not just the DPASelections one I’ve chosen for this example.

If I update the context to return ObjectSet (still using the POCO entities) rather than IObjectSet it all works fine. When using IObjectSet and the extension method and step through the code I see that the extension method is completing correctly with a call to the ObjectQuery we’re casting to but the included entities are never returned on the graph. As said, this works perfectly when I don’t interface out the Context and return ObjectSet properties hence calling Include directly on ObjectSet.

I’m not getting any errors on executing the query so this isn’t the same as several other questions on SO which refer to compiled queries.

Has anyone else experienced problems with this extension method implementation or can anyone spot what I’m doing wrong here?

Any help very much appreciated.

        static void Main(string[] args)
    {
        using (var context = new AssocEntities())
        {
            context.ContextOptions.LazyLoadingEnabled = false;
            Candidate candidate = context.Candidates
                                        .Include("DPASelections.DPAOption")
                                        .SingleOrDefault(c => c.Number == "N100064");

            //Count is 0 when using ext. method and IObjectSet through AssocContext but correct when using Include
            //on ObjectSet through AssocContext
            Console.WriteLine("DPASelection count = {0}",candidate.DPASelections.Count);

            //This is always null when using IObjectSet and ext. method but populated
            //when using Include on ObjectSet
            var option = candidate.DPASelections.First().DPAOption;

            Console.WriteLine("First DPAOption = {0} : {1}",option.Id,option.Text);

        }

        Console.ReadLine();
    }
}

public static class Extensions
{
    public static IQueryable<TSource> Include<TSource>(this IQueryable<TSource> source, string path)
    {
        var objectQuery = source as ObjectQuery<TSource>;

        if (objectQuery != null)
        {
            objectQuery.Include(path);
        }

        return source;
    }
}

//Subset of custom context implementing IObjectSet as returns.
//Works fine when I return ObjectSet rather than IObjectSet and use
//the Include method directly
public partial class AssocEntities : ObjectContext
{
    public const string ConnectionString = "name=AssocEntities";
    public const string ContainerName = "AssocEntities";

    #region Constructors

    public AssocEntities()
        : base(ConnectionString, ContainerName)
    {
        this.ContextOptions.LazyLoadingEnabled = true;
    }

    public AssocEntities(string connectionString)
        : base(connectionString, ContainerName)
    {
        this.ContextOptions.LazyLoadingEnabled = true;
    }

    public AssocEntities(EntityConnection connection)
        : base(connection, ContainerName)
    {
        this.ContextOptions.LazyLoadingEnabled = true;
    }

    #endregion

    #region IObjectSet Properties

    public IObjectSet<Address> Addresses
    {
        get { return _addresses ?? (_addresses = CreateObjectSet<Address>("Addresses")); }
    }
    private IObjectSet<Address> _addresses;

    public IObjectSet<Answer> Answers
    {
        get { return _answers ?? (_answers = CreateObjectSet<Answer>("Answers")); }
    }
    private IObjectSet<Answer> _answers;

    public IObjectSet<Candidate> Candidates
    {
        get { return _candidates ?? (_candidates = CreateObjectSet<Candidate>("Candidates")); }
    }
}

And the model…
alt text

  • 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-31T22:18:28+00:00Added an answer on May 31, 2026 at 10:18 pm

    I needed to replace objectQuery.Include(path); with objectQuery = objectQuery.Include(path);

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

Sidebar

Related Questions

Could anyone help me with the code needed to get a stacked bar using
Could anyone help me to understand following line of code: sol< ?=f((1<< n)-1,i,0)+abs(P[i])*price; I
Could anyone please help me convert this code to vb.net, I have tried it
Could anyone please help me using C# Api in Z3. I have no idea
Could anyone help with this please? I am pulling the results in below from
Could anyone help me with this problem? Code zip is here: (link taken down)
Ok so could anyone please help me out with the VB for auto entering
I need to get substed drive letter in Perl. Could anyone kindly help me?
I wonder if anyone could help me with a problem I've been having. I
Im asking to see if anyone could help me with my problem which is

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.