WHERE CLAUSE NOT GIVING THE DESIRED VALUE IN LINQ

Goti Bandu

Total Post:119

Points:835
Posted by  Goti Bandu
LINQ 
 952  View(s)
Ratings:
Rate this:

I’m attempting to write a search routine and part of it includes the following code:

string searchValue = Server.HtmlEncode(RadSearchBox.Text.ToLower());

 

var injurySearchList = (from i in injuryObj

                        where i.IsDeleted == false &&

                        (

                            i.ResultOther == true ? "ResultOther".ToLower().Contains(searchValue) : i.IncidentID.ToString().Contains(searchValue)

                            || i.BodyPartHead == true ? "BodyPartHead".ToLower().Contains(searchValue) : i.IncidentID.ToString().Contains(searchValue)

                        )

                        select i.IncidentID).ToList();

I’m unable to search the bit values for a string.I use the ternary operator to evaluate if it’s true,If the bit value is false, I’d prefer to exclude that line from the WHERE clause but was unable to come up with any clever ideas


Please suggest me

  1. Sumit Kesarwani

    Post:378

    Points:2694
    Re: Where clause not giving the desired value in Linq

    Hi Goti, 

    try the below code:

    var injurySearchList = (from i in injuryObj

                            where i.IsDeleted == false &&

                            (

                                (i.ResultOther == true

                                     ? "ResultOther".ToLower().Contains(searchValue)

                                     : i.IncidentID.ToString().Contains(searchValue))

                             || (i.BodyPartHead == true

                                     ? "BodyPartHead".ToLower().Contains(searchValue)

                                     : i.IncidentID.ToString().Contains(searchValue))

                                )

                            select i.IncidentID).ToList();

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!