简体   繁体   中英

need help to build linq query

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM