Reputation: 181
I am facing problem to create Linq query following is example following are some data which is available in Db
data-
7604
76041010
7505
750511
and i have another number like which i need to search in above data like
1) 76041010 this number should take 76041010 code from above data
2) 760458688 this number should take 7604 code from above data
3) 7505110022 this number should take 750511 code from above data ,
I need to retrieve maximum matched number from db, I need query please help me to build linq query.
Upvotes: 0
Views: 57
Reputation: 2800
Not the most elegant solution, but produces the result you're expecting:
var result = data.Select(x => x.ToString())
.Where(x => input.ToString().StartsWith(x))
.OrderByDescending(x => x.Length)
.FirstOrDefault();
Upvotes: 1