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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:22:24+00:00 2026-05-13T19:22:24+00:00

I’ve inherited this project from the previous guy, and I’m presently in the process

  • 0

I’ve inherited this project from the previous guy, and I’m presently in the process of switching over a number of assembled-from-string SQL queries into LINQ to SQL, which I’m told is what makes life in .NET worth living. However, I’m running into problems filtering a Many-to-Many relationship.

The system is a Project Management intranet affair. The primary object/table of note is Project. Project has many Markets, which uses an intermediary table linkProjectMarkets to link them. There’s plenty of other stuff going on, but I can take care of that if I can understand this problem, it’s all similar.

In short, I can’t for the life of me take a list of Market IDs provided by a set of checkboxes, and filter the list of projects down to those which have a relation to the markets whose ids are provided.

The gist of the schema is:

Project: int id, …(a bunch of metadata)
linkProjectMarkets: int projectId, int marketId
Market: int id, string summary

All of this, any many, many more, is defined in a dbml file and accompanying generated code. To facilitate access between project and market, project has the following addon method:

public partial class project
{
    public EntitySet<market> markets
    {
        get
        {
            return (EntitySet<market>)from lpm in this._linkProjectMarkets
                                      select lpm.market;
        }
        set
        {
            var set = (EntitySet<market>)from lpm in this._linkProjectMarkets
                                         select lpm.market;
            set.Assign(value);
        }
    }
}

Here’s the most recent bit of code I’m attempting to use to filter the set of all projects:

var projects = 
from p in db.projects
select p;

//MarketFilterList is an IEnumerable of market ids created from the checked checkboxes.
if(MarketFilterList.Count() > 0){
    foreach (int mid in MarketFilterList){
        projects = projects.Where(p => p.markets.Select(m => m.id).Contains(mid));
        /*
        Causes "Member access 'Int32 id' of 'PMIS2.market' not legal on type 
        'System.Data.Linq.EntitySet`1[PMIS2.market]."
        */
    }

}

There are a number of other filters to apply, which is why I’m doing it in steps instead of one LINQ statement.

I checked out the designer code; market in linkProjectMarkets is public, and id is public in market. It’s my first real C#/.NET experience, so maybe I just don’t understand the error message. Apologies if I’ve given too much, not enough, or not the right information. Please help!

P.S. I already tried LINQ to Entities, and I would have to have a really good reason to try it again.

Edit

Here’s something else I tried:

projects = projects.Where(
    p => MarketFilterList.Intersect(from m in p.markets select m.id).Count() > 0
);

That one told me:

Local sequence cannot be used in LINQ to SQL implementation of query operators except the Contains() operator.

Edit again

Here’s the solution based on JTew’s answer. If anyone has the real reason why project can’t access market directly I’d love to hear it.

projects = projects.Where(p => (from lpm in db.linkProjectMarkets
                                where MarketFilterList.Contains(lpm.marketId)
                                select lpm.project).Contains(p));
  • 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-13T19:22:24+00:00Added an answer on May 13, 2026 at 7:22 pm

    I would do the following:

    var projMarkLink = from lpm in db.linkProjectMarkets select lpm;
    

    Establish an IQueryable then on subsequent lines add filters:

    foreach (int mid in MarketFilterList){
         projMarkLink = projMarkLink.Where(l => l.mid == mid);
    }
    

    Then select the result that you need:

    return (from lpm in projMarkLink
           from p in projMarkLink.Projects  
           select p).ToList();
    

    You can take this one step further and remove the loop, have a read of this stackoverflow question.

    return (from lpm in projMarkLink
           from p in projMarkLink.Projects  
           where lpm.Contains(MarketFilterList)
           select p).ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know how can I replace this 2 symbol below from the string
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want to count how many characters a certain string has in PHP, but
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.