Click here to Skip to main content
15,906,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to search data based on number whihc is contains search numbers in linq or lamdaexperssion

data is below

Id Name ContactNumber

1  A    9043484888
2  B    8938938983


select * from contactDetails where number like '%484%'


What I have tried:

select * from contactDetails where number like '%484%'
Search value 484

var result = details.Where(e=>e.ContactNumber.ToString().Contains(searchvalue)).ToList
Posted
Updated 4-Oct-18 0:47am
Comments
F-ES Sitecore 4-Oct-18 6:05am    
Don't store phone numbers as number types, they're not numbers. Storing as a number is going to give you many different problems in the future, it is vital you use appropriate types. Change the field to a varchar or nvarchar as appropriate.

1 solution

Always store phone numbers in string datatypes: they aren't numbers because you can't do any maths with them: what is your phone number plus my phone number? What would it possibly be?

In addition, phone numbers aren't just digits: +44 (0777) 777 7777 is a valid phone number format - the +44 indicates it's a UK number, the (0777) is an area code within the UK, and the spaces make it easier for humans to read. You can;t store any of that in a numeric value!

When you store them as strings, you can use LIKE on them, but not with numbers.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900