0

我得到以下代码:

string query = "select * from dbo.Personnel where PersonnelId in ({0})";
string param = "1, 2";
var test = model.ExecuteStoreQuery<Personnel>(query, param).ToList();

我收到以下错误:“将 nvarchar 值 '1, 2' 转换为数据类型 int 时转换失败。”...

有谁知道如何解决这个问题?我想要的是select * from dbo.Personnel where PersonnelId in (1, 2),但数字可以是任何数字......

4

1 回答 1

0

Don't send param to ExecuteStoreQuery, just replace {0} with param

string param = "1, 2";
string query = string.Format("select * from dbo.Personnel where PersonnelId in ({0})", param);

or

string query = "select * from dbo.Personnel where PersonnelId in ({0})";
query = query.Replace("{0}",param);

var test = model.ExecuteStoreQuery<Personnel>(query).ToList();
于 2012-11-28T22:04:56.497 回答