T-SQL IsNumeric() and Linq-to-SQL

前端 未结 4 1893
再見小時候
再見小時候 2021-01-12 09:49

I need to find the highest value from the database that satisfies a certain formatting convention. Specifically, I would like to find the highest value that looks like

4条回答
  •  有刺的猬
    2021-01-12 10:55

    As you said, there is no translation for IsNumeric from LINQ to SQL. There are a few options, you already wrote database function and stored procedure down. I like to add two more.

    Option 1: You can do this by mixing LINQ to SQL with LINQ to Objects, but when you've got a big database, don't expect great performance:

    var cols = (from c in db.Table where c.StartsWith("EU") select c).ToList();
    var stripped = from c in cols select int.Parse(c.Replace("EU", ""));
    var max = stripped.Max();
    

    Option 2: change your database schema :-)

提交回复
热议问题