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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:44:15+00:00 2026-06-12T22:44:15+00:00

I have C# Lambda linq query as follow: public IQueryable<CtArticleDetail> GetArticleDetailsByTagNames(string tagNames) { return

  • 0

I have C# Lambda linq query as follow:

public IQueryable<CtArticleDetail> GetArticleDetailsByTagNames(string tagNames)
{
    return db.CtArticleTags.Where(m => tagNames.Contains(m.CtTag.Name) 
                                       && m.CtArticleDetail.ExpirationDate > DateTime.Now
                                       && m.CtArticleDetail.ArticleStatusId == (int)ArticleStatus.Published)
                           .Select(m => m.CtArticleDetail).OrderBy(x => x.LiveDate).Distinct();
}

This returns slightly wrong data list because of “Contains”. The parameter actually comes this format: EG ( “AterSale,GeneralSale”). The result list contains other sale type articles.EG (“Sale” or “ImportedSale”).

The reuslt list should be exact list as parameter passed. Can anyone pls advice ?

var mustContain = new[] {"A", "B");

var foos = new  List<Foo>(){
     new Foo1 {Tags = "A"},
     new Foo1 {Tags = "B"},
     new Foo2 {Tags = "A"},
     new Foo2 {Tags = "C"}
};   

I just need Foo1 if mustcontain is A,B

  • 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-12T22:44:16+00:00Added an answer on June 12, 2026 at 10:44 pm

    If i understand you correctly tagNames is a string which is a list of tagNames separated by comma. Then you could use String.Split:

    String[] tags = tagNames.Split(new[]{","}, StringSplitOptions.RemoveEmptyEntries);
    return db.CtArticleTags.Where(m => tags.Contains(m.CtTag.Name) && m.CtArticleDetail.ExpirationDate > DateTime.Now
                && m.CtArticleDetail.ArticleStatusId == (int)ArticleStatus.Published)
                .Select(m => m.CtArticleDetail).OrderBy(x => x.LiveDate).Distinct();
    

    According to your comment

    What about If I need multiple condition. EG. Let say – ‘tags’ contains
    sale,aftersale. I like to retrieve that article must have SALE and
    AFTERSALE tagged. Not only SALE or AFTERSALE

    You can use Enumerable.All, here’s a Linq-To-Objects example which you can hopefully convert to Linq-To-Entities:

    var mustContain = new[] { "A", "B" };
    var foos = new List<Foo>() { 
        new Foo{Tags="A,B"},
        new Foo{Tags="B"},
        new Foo{Tags="C,A"},
        new Foo{Tags="D"},
        new Foo{Tags="B,A,C"},
        new Foo{Tags="F,C,A,D,B"},
    };
    
    var result = foos
        .Where(f => mustContain.All(mc =>  
            f.Tags.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                  .Contains(mc))); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a LINQ query that looks like this: public IEnumerable<Foo> SelectFooBars() { return
I have used this function to convert string to bits. def a2bits(chars): return bin(reduce(lambda
I have a simple LINQ lambda join query but I want to add a
I have the following LINQ query: return (from r in Repository.Query<Measurement>() where r.Postal.ToLowerInvariant() ==
I have a LINQ query that uses lambda syntax: var query = books .Where(book
I have a following simple code: def get(): return [lambda: i for i in
I have model like this: scope :search_posts, lambda { |query| mega_posts.where( title LIKE ?
I have a linq query in which I need to specifically do a left
I'm trying to convert this linq query to lambda var query = (from a
I am using LINQ to EF and have the following LINQ query: var results

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.