【发布时间】:2015-02-12 04:18:49
【问题描述】:
我正在尝试使用字符串列上的 where 子句选择行,并与我的变量 zip(它是 int)进行比较。这可能吗?我在 lambda 中尝试过 int.Parse() 但这不起作用。由于我使用的是 .NET 3.5,因此我似乎无法使用 SQLFunctions 调用。
下面的 PostcodeStart/PostcodeEnd 是 nvarchar,而 zip 是 int。
var re = postCodes.Where(
x => x.PostcodeStart <= zip && x.PostcodeEnd >= zip);
【问题讨论】:
-
你试过
(int) x.PostcodeStart吗? -
是的,这不允许我编译。无法将字符串类型转换为 int 类型...
-
究竟有什么不能与 int.Parse 一起使用?
-
这是我在尝试使用 int.Parse() 时遇到的错误:Method 'Int32 Parse(System.String)' has no supported translation to SQL.
-
Convert.ToInt32(string_here)怎么样?