tags:

views:

89

answers:

1

Is there a better way to create the following linq to sql query? I am trying to get all Company Names that start with a number [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;

Many Thanks

+4  A: 

What about:

var suppliers = from s in context.Supplier where 
    SqlMethods.Like(s.CompanyName, "[0-9]%")
select s;
Konamiman
Duh! Thanks konamiman
Rippo
By the way I didn't know the existence of the SqlMethods class. Can it be extended with custom methods?
Konamiman
I am not too sure.. maybe you can ask a question on Stack Overflow...!
Rippo