如何将字符串转换为int?无下面做的作品:Linq int字符串
from s in ctx.Services
where s.Code.ToString().StartsWith("1")
select s
from s in ctx.Services
where Convert.ToString(s.Code).StartsWith("1")
select s
from s in ctx.Services
where ((string)s.Code).ToString().StartsWith("1")
select s
编辑
我得到的错误是:
LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression
前两个应该工作......你能详细说明“以下哪一项......没有工作”的含义? – 2009-08-04 15:54:56
你只是没有得到任何结果吗?您是否确认“代码”列包含以“1”开头的值? – Keith 2009-08-04 15:55:49
www.linqpad.net非常适合学习Linq(以及.NET中的其他任何东西)。它是免费的,强烈推荐。另外,其19美元的Intellisense非常棒。 – 2009-08-04 16:01:00