ExecuteStoreQuery 和 "WHERE IN ({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)但数字可以是任何数字......

不要将参数发送到ExecuteStoreQuery,只需将{0}替换为param

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

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

相关内容

  • 没有找到相关文章

最新更新