简体   繁体   English

需要帮助来构建linq查询

[英]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 我面临创建Linq查询的问题,以下是示例,以下是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. 我需要从数据库中检索最大匹配数,我需要查询,请帮助我构建linq查询。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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