Home > DeveloperSection > Forums > Where clause not giving the desired value in Linq
Goti Bandu

Total Post:119

Points:835
Posted on    November-17-2014 11:22 PM

 LINQ LINQ 
Ratings:


 1 Reply(s)
 610  View(s)
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



Sumit Kesarwani

Total Post:378

Points:2694
Posted on    November-17-2014 11:43 PM

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();


Don't want to miss updates? Please click the below button!

Follow MindStick