C# Linq to SQL:如何表达“CONVERT([...] AS INT)”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/992189/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 05:05:06  来源:igfitidea点击:

C# Linq to SQL: How to express "CONVERT([...] AS INT)"?

c#linqlinq-to-sql

提问by Timwi

In MSSQL you can convert a string into an integer like this:

在 MSSQL 中,您可以将字符串转换为整数,如下所示:

CONVERT(INT, table.column)

Is there any C# expression that Linq to SQL would translate to this?

Linq to SQL 是否有任何 C# 表达式会转换成这个?

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:

在 C# 中,您通常可以通过使用 来执行相同的操作int.Parse(),但不幸的是,尝试int.Parse()在 Linq 查询中使用会导致错误:

Method 'Int32 Parse(System.String)' has no supported translation to SQL.

方法“Int32 Parse(System.String)”不支持转换为 SQL。

Is there any C# expression that Linq to SQL would translate to CONVERT(INT, ...)?

有没有 Linq to SQL 会转换成的 C# 表达式CONVERT(INT, ...)

采纳答案by Eric

C# has Convert.ToInt32()which should do what you're looking for.

C# 有Convert.ToInt32()which 应该做你正在寻找的。

回答by JP Alioto

Convert.ToInt32should work. Check out this articlefor information on the translations.

Convert.ToInt32应该可以工作。查看这篇文章以获取有关翻译的信息。