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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:11:38+00:00 2026-05-30T16:11:38+00:00

I’m having a trouble filtering/ joining in-memory object lists with Linq to objects, and

  • 0

I’m having a trouble filtering/ joining in-memory object lists with Linq to objects, and for what would normally be a trivial SQL query…

Scenario:
Have a json service(.asmx) allows client to make a DB call through Entity Framework wrapped sproc (function import). In this case a [Web Method] “GetArticles(int [] TagIds)”
I’m now looking to cache this data to save on DB calls and apply filters to the cached collection.

Data:

  • Many to many relationship with 2 Entities: Articles, Tags
  • Articles can have many tags, and tags can be associated with many articles, ( so extra link table ‘ArticlesTags’)

The web service filter param will contain an array of TagId’s that returned articles can have.

So my baseline SQL query would look like so

SELECT DISTINCT a.*
FROM Article a INNER JOIN ArticlesTags at ON a.ArticleId = at.ArticleId
WHERE at.TagId in (0, 1.. 'list of tag ids')

I’m hitting a number of snags –
EF wrapped sprocs don’t allow SQL 2008 (Table Value Parameters) so i can’t pass in TagId list filter in the preferred format.
I have found an example where two result sets can be returned from one sproc call which may get around that.
So once I have the two collections (Articles and ArticlesTags) which I intend to cache, how does one join and subsequently filter based on the possible TagId’s filter param with linq-to-objects?

  • 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-30T16:11:39+00:00Added an answer on May 30, 2026 at 4:11 pm

    Here is one way to “rewrite” your SQL query in LINQ:

    class Article {
        public int ArticleId;
        public string ArticleName;
        // Other fields...
    }
    
    class ArticleComparer : IEqualityComparer<Article> {
        public bool Equals(Article x, Article y) {
            return x.ArticleId == y.ArticleId && x.ArticleName == y.ArticleName;
        }
        public int GetHashCode(Article obj) {
            return obj.ArticleId.GetHashCode();
        }
    }
    
    class ArticlesTag {
        public int TagId;
        public int ArticleId;
        // Other fields...
    }
    
    class Program {
    
        static void Main(string[] args) {
    
            // Test data:
    
            var articles = new[] {
                new Article { ArticleId = 1, ArticleName = "Article A" },
                new Article { ArticleId = 2, ArticleName = "Article B" },
                new Article { ArticleId = 3, ArticleName = "Article C" }
            };
    
            var article_tags = new[] {
                new ArticlesTag { TagId = 1, ArticleId = 1 },
                new ArticlesTag { TagId = 2, ArticleId = 1 },
                new ArticlesTag { TagId = 3, ArticleId = 1 },
                new ArticlesTag { TagId = 4, ArticleId = 2 },
                new ArticlesTag { TagId = 5, ArticleId = 2 },
                new ArticlesTag { TagId = 6, ArticleId = 3 },
                new ArticlesTag { TagId = 7, ArticleId = 3 }
            };
    
            var tag_ids = new HashSet<int>(new[] { 2, 3, 6 });
    
            // JOIN "query":
    
            var q = (
                from article in articles
                join article_tag in article_tags
                    on article.ArticleId equals article_tag.ArticleId
                where tag_ids.Contains(article_tag.TagId)
                select article
            ).Distinct(new ArticleComparer());
    
            foreach (var article in q)
                Console.WriteLine(
                    string.Format(
                        "ArticleId = {0}\tArticleName = {1}",
                        article.ArticleId,
                        article.ArticleName
                    )
                );
    
        }
    
    }
    

    This prints:

    ArticleId = 1   ArticleName = Article A
    ArticleId = 3   ArticleName = Article C
    
    • 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'm having trouble keeping the paragraph square between the quote marks. In firefox the
I would like to count the length of a string with PHP. The string
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
i got an object with contents of html markup in it, for example: string
I would like to run a str_replace or preg_replace which looks for certain words
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

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.