有没有更好的方法来创建以下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;


非常感谢

最佳答案

关于什么:

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

关于c# - linq to sql-如何重写以下内容,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1455310/

10-13 09:30