C#中的LINQ to SQL:如何前preSS" CONVERT([...] AS INT)QUOT ;? [英] C# Linq to SQL: How to express "CONVERT([...] AS INT)"?
问题描述
在MSSQL您可以将字符串转换为这样一个整数:
In MSSQL you can convert a string into an integer like this:
CONVERT(INT, table.column)
有没有C#的前pression的LINQ到SQL将转化呢?
Is there any C# expression that Linq to SQL would translate to this?
在C#中,你可以正常做同样的使用 int.Parse()
,但不幸的是,试图用 int.Parse()
在一个错误LINQ查询的结果:
In C# you can normally do the same by using int.Parse()
, but unfortunately, trying to use int.Parse()
in a Linq query results in an error:
方法的Int32解析(System.String)没有支持转换为SQL。
Method 'Int32 Parse(System.String)' has no supported translation to SQL.
有没有C#的前pression的LINQ到SQL会转化为 CONVERT(INT,...)
?
Is there any C# expression that Linq to SQL would translate to CONVERT(INT, ...)
?
推荐答案
C#有 Convert.ToInt32()
应该做你要找的东西。
C# has Convert.ToInt32()
which should do what you're looking for.
这篇关于C#中的LINQ to SQL:如何前preSS" CONVERT([...] AS INT)QUOT ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!