Dapper where Id in的解决方案

 

简单记一下,一会出去有点事情~

我们一般写sql都是==》update NoteInfo set NDataStatus=@NDataStatus where NId in (@NIds)

Dapper生成的sql是:

也就自然出错了:

 

简单修改一下:

int i = await NoteInfoBLL.ExecuteAsync("update NoteInfo set NDataStatus=@NDataStatus where NId in @NIds", new
{
  NDataStatus = status,
  NIds = ids.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)
});

Dapper生成sql:(类型再转换一下就ok了,这边只是说下方法,先闪了)

exec sp_executesql N'update NoteInfo set NDataStatus=@NDataStatus where NId in (@NIds1,@NIds2,@NIds3)',N'@NDataStatus int,@NIds1 nvarchar(4000),@NIds2 nvarchar(4000),@NIds3 nvarchar(4000)',@NDataStatus=99,@NIds1=N'1',@NIds2=N'2',@NIds3=N'3'

posted @ 2016-09-07 17:26  毒逆天  阅读(2428)  评论(0编辑  收藏  举报