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

  • Home
  • SEARCH
  • 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 8416717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:50:38+00:00 2026-06-10T01:50:38+00:00

I have a many to many relationship in EF Code First between Contacts and

  • 0

I have a many to many relationship in EF Code First between Contacts and Lists. ProxyCreation and LazyLoading are disabled to allow serialization of the entities.

I have a query that is meant to return contacts that are in a given list.

// GET api/Contacts
        [Queryable]
        public IQueryable<Contact> GetContacts(int bulkListId)
        {
            var bulkList = db.BulkLists.Include(c => c.Contacts).Where(c => c.ID == bulkListId).SingleOrDefault();

            if (bulkList == null)
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));

            return bulkList.Contacts.AsQueryable().OrderBy(c => c.ID).Include(c => c.AddressBookType).Include(c => c.BulkLists);
        }

Although this works, it doesn’t work as intended. It results in the correct set of contacts who are in a given list but these contacts only have that list populated in their Lists property of the relationship. So when this is serialized and gets back to the client it hides the other lists that the contacts are members of.

I can’t see how the query is filtering it in this way and how I might change it to include the full set of lists. Any advice would be very much appreciated.

  • 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-10T01:50:39+00:00Added an answer on June 10, 2026 at 1:50 am

    You’re cheating! 🙂

    By adding AsQueryable() to bulkList.Contacts you make it possible to continue with Include without making the compiler complain. BUT…

    As per MSDN on DbExtensions.Include:

    This extension method calls the Include(String) method of the IQueryable source object, if such a method exists. If the source IQueryable does not have a matching method, then this method does nothing.

    (emphasis mine)

    And EntityCollection does not have an Include method, so nothing happens.

    You’ll have to expand the include list in your first statement, probably like so:

    db.BulkLists
        .Include(c => c.Contacts.Select(c => c.AddressBookType))
        .Include(c => c.Contacts.Select(c => c.BulkLists))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a EF Code First One-To-Many relationship. It's essentially a Parent/Child relations as
I'm using EF 4.3 code-first. I have a many-to-many relationship. I am trying in
I have many-to-many linking table between two entities, datacenters and projects, in legacy code.
I have the following many-to-many relationship set up in my db. Mapped using Code-First
I have a many-to-many relationship between two tables, let's say Friends and Foods. If
I have a many-to-many relationship between users and groups and I have a table
I have a many-to-many relationship between User s and Task s. I want the
I'm trying to create a many-to-many relationship using EF code first in my MVC
I have a one-to-many relationship between Part and Params (a Part has many Params).
How do you represent a many-to-many relationship in the EF4 Code-First CTP3? For example

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.