We help IT Professionals succeed at work.

.Tolower() is not working in linq query

list = (from sr in dbContext.SERVICE_REQUEST
             join sc in dbContext.SERVICE_CUSTOMER on sr.CUSTOMER_ID equals sc.CUSTOMER_ID)
              where  (sr.SERVICE_REQUEST_NO.ToLower().Contains(objtobeAdvSearch.ServiceRequestNumber.ToLower()))

from above is sample query. my task is serach value,for that iam comparing oracle database filed and search value(objtobeAdvSearch). now i am converting tolower for comparision. but not working can u plz help me regarding this
Comment
Watch Question

Ryan ChongSoftware Team Lead

Commented:
few things to check..

1. what's the variable type of sr.SERVICE_REQUEST_NO ? Object, String, etc?
2. what's the variable type of objtobeAdvSearch.ServiceRequestNumber ? Object, String, etc?

Author

Commented:
STRING
Ryan ChongSoftware Team Lead

Commented:
when you mentioned "not working", is that no result was selected or generated an error?

if it's no result, can you putting break point and then debug to compare what's the values for:

sr.SERVICE_REQUEST_NO.ToLower()
objtobeAdvSearch.ServiceRequestNumber.ToLower()

?
list = (from sr in dbContext.SERVICE_REQUEST
             join sc in dbContext.SERVICE_CUSTOMER on sr.CUSTOMER_ID equals sc.CUSTOMER_ID)
where  (sr.SERVICE_REQUEST_NO.IndexOf(objtobeAdvSearch.ServiceRequestNumber, StringComparison.OrdinalIgnoreCase) != -1))

Use IndexOf along with StringComparison.OrdinalIgnoreCase option. It should work.
Prakash SamariyaIT Professional
Top Expert 2015

Commented:
where  (sr.SERVICE_REQUEST_NO.Equals(objtobeAdvSearch.ServiceRequestNumber,StringComparison.OrdinalIgnoreCase))