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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:05:15+00:00 2026-05-30T23:05:15+00:00

I’m having problems with the following Linq query (demandNb is a filter option, as

  • 0

I’m having problems with the following Linq query (demandNb is a filter option, as a string):

Return (From auto In entity.DEMDT_AUTMT _
    Where (String.IsNullOrEmpty(demandNb) OrElse auto.DEMND_NB = demandNb) _
    Order By auto.NO_DEMND Descending _
    Select auto).ToList()

My goal is to get all demands for the database if the filter fields is empty. If there is a filter, the function should return all demands that match the filter.

Currently, when I try to convert the IQueryable collection to a list using .ToList(), the following error is thrown:

Conversion from string "" to type 'Double' is not valid.

The problem is, when demandNb is equal to “”, this instruction auto.DEMND_NB = demandNb is still executed, throwing a conversion error.

When I remove the part after OrElse, everything works fine (although this is not the behavior I want, I want the filter to work afterall!). I have also tried to put the result in a variable (which works), and then convert it to a list, and the error is only thrown when .ToList() is called. Wierd…

Is there something I am not seeing, and why is not OrElse working as intended?

Edit:

I will be implementing several more filter fields like this (like demand owner, demand date, etc), so I cannot verify the if the filter is empty before executing the query

  • 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-30T23:05:16+00:00Added an answer on May 30, 2026 at 11:05 pm

    If I had to guess, I’d say auto.DEMND_NB is of type Double, and demandNb is obviously a string. This has nothing to do with the OrElse: you’re just trying to compare two values of non-compatible types.

    Since the value of demandNb is not tied to each row in the data, I’d suggest doing something like this (pardon the C#):

    var autos = entity.DEMDT_AUTMT;
    if(!string.IsNullOrEmpty(demandNb))
    {
        var demandNbDouble = double.Parse(demandNb);
        autos = autos.Where(auto => auto.DEMND_NB == demandNbDouble);
    }
    autos = autos.OrderBy(...);
    
    • 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
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Does anyone know how can I replace this 2 symbol below from the string
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
I've got a string that has curly quotes in it. I'd like to replace
Specifically, suppose I start with the string string =hello \'i am \' me And
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.