linq to sql - 我如何重写以下内容

时间:2009-09-21 16:02:12

标签: c# linq-to-sql

有没有更好的方法来创建以下linq to sql查询?我想让所有公司名称以数字[0-9] ...

开头
var suppliers = from s in context.Supplier where 
    SqlMethods.Like(s.CompanyName, "0%") ||
    SqlMethods.Like(s.CompanyName, "1%") ||
    SqlMethods.Like(s.CompanyName, "2%") ||
    SqlMethods.Like(s.CompanyName, "3%") ||
    SqlMethods.Like(s.CompanyName, "4%") ||
    SqlMethods.Like(s.CompanyName, "5%") ||
    SqlMethods.Like(s.CompanyName, "6%") ||
    SqlMethods.Like(s.CompanyName, "7%") ||
    SqlMethods.Like(s.CompanyName, "8%") ||
    SqlMethods.Like(s.CompanyName, "9%")
 select s;

非常感谢

1 个答案:

答案 0 :(得分:4)

怎么样:

var suppliers = from s in context.Supplier where 
    SqlMethods.Like(s.CompanyName, "[0-9]%")
select s;