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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:26:16+00:00 2026-06-13T14:26:16+00:00

In my example i want to get promotion elements for a promo code name

  • 0

In my example i want to get promotion elements for a promo code name that is provided if name is not provided then take all available promotions.

var result = from row in promoCodes.AsEnumerable() 
             where  (
                 !String.IsNullOrEmpty(fieldTitle) && 
                 !String.IsNullOrEmpty(filterValue) && 
                 row[fieldTitle].Equals(filterValue)
             ) || true
             select new PromoCodeInfoContainer
             {
                 BannerLink = row["BannerLink"] as string
                 ....
             };

I tried to follow SQL technique where if no conditions provided then OR will be whatever that doesn’t impact selection (|| true). In linq this didn’t work, it always returns all entries regardless of “fieldTitle” and “filterValue” are not empty. Can anybody suggest a right way to do it?

  • 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-13T14:26:17+00:00Added an answer on June 13, 2026 at 2:26 pm

    Firstly, remove the || true – that will return every row, always – hence the problem.

    One nice way to do this would be composition – this then avoids the need to test the fieldTitle / fieldValue for every row when they have values, or do anything much at all per-row if they are blank:

    var query = promoCodes.AsEnumerable();
    if(!string.IsNullOrEmpty(fieldTitle) && !string.IsNullOrEmpty(fieldValue))
    {
        query = from row in query
                where filterValue.Equals(row[fieldTitle])
                select row;
    }
    var result = from row in query
                 select new PromoCodeInfoContainer {...}
    

    Note I also reversed the Equals so that the thing-we-know-isn’t-null is on the left; although depending on the data-types, Equals(x,y) or x == y may be preferable.

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

Sidebar

Related Questions

I want to get all photo fids albums. For example, I have albums and
If I want to get a user that has the email address of 'me@example.com',
I want if my visitors go to subdomain.example.com that they get redirected to anothersubdomain.example.com
Is there a way to get the DataGridTextColumn name in code behind? For example:
I have set of 100000 String. And for example I want to get all
I have a String like : name:lala,id:1234,phone:123 but for example I want to get
I want to get 100 and example from this string ?connect:100/username:example/ I searched in
I want to get the single digits from two digits.for example if 36 I
I want to get N random numbers whose sum is a value. For example,
I got the chat example working from Atmosphere, and now I want to get

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.