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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:57:59+00:00 2026-05-21T22:57:59+00:00

I’m building a repository method (Entity Framework) to take in a collection of ids

  • 0

I’m building a repository method (Entity Framework) to take in a collection of ids supplied by checkboxes in a form as part of a CMS, and updating a lookup table (entity set) that relates topics to publications.

I have this method in a respository:

public void AttachToTopics(int pubId, IQueryable<int> topicsForAssociation, IQueryable<int> topicsSubset, int primaryTopicId)

{

    // EVERYTHING IS FINE IF I INSERT A MANUAL COLLECTION  OF int LIKE THIS:
    // var priorAssociatedTopics = new[] { 2 }.AsQueryable();  // 

    // BUT WHAT I REALLY NEED TO WORK IS THIS:  
    IQueryable<int> priorAssociatedTopics = ListTopicIdsForPublication(pubId);

    var priorAssociatedTopicsToExamine = priorAssociatedTopics.Intersect(topicsSubset);

    var topicsToAdd =
        associatedTopics.Intersect(topicsSubset).Except(priorAssociatedTopicsToExamine);

    foreach (var topicToAdd in topicsToAdd)
        AttachToTopic(pubId, topicToAdd);


    foreach (var topicToRemove in priorAssociatedTopicsToExamine.Except(associatedTopics))
        DetachFromTopic(pubId, topicToRemove);

}

AttachToTopics chokes on the first foreach loop, yielding this error message:

This method supports the LINQ to Entities infrastructure and is not intended to be used directly from your code.

But the problem is really with the first line: the repository method called on that line provides the appropriately typed collection into priorAssociatedTopics, and Intellisense has no problem with explicitly typing it as IQueryable (normally, I’d use var), and the debugger shows that this variable holds a collection of integers.

public IQueryable<int> ListTopicIdsForPublication(int pubId)
{
    var topics = from x in DataContext.TopicPublications where x.PublicationId == pubId  select x;
    return topics.Select(t => t.Id);
}

However, back in attachToTopics, my topicsToAdd collection doesn’t get populated, and its Results View in debug holds the aforementioned error message.

Curiously, if I switch in a manually generated IQueryable collection of ints for priorAssociatedTopics (see comment in code, above) the foreach loop works fine. So I beleive I need to find some other way to get priorAssociatedTopics populated with ints from a method call in my repository.

Any clue out there?

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

    Is there any reason that ListTopicIdsForPublication can’t return an IEnumerable<int> or an IList<int> in this case? If so, adding a .ToList() at the end of topics.Select(t => t.ID) will ensure that the query gets run at that point.

    It’s not so much that it’s IQueryable<int> that’s causing the problem, but rather IQueryable<int> from DataContext.TopicPublications. It looks like it’s losing it’s contextual data information and that’s why you’re getting the exception.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text

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.