Dapper中條件為In的寫法

2022-05-28 13:45:12 字數 772 閱讀 5283

conn.query("select * from users s where s.id in (@ids) ",new })

conn.query("select * from users s where s.id in (@ids) ",new )

用了之後出現,

system.data.sqlclient.sqlexception:「「,」附近有語法錯誤。」

這樣的提示,

跟蹤sql語句時發現按以上方法生成的sql語句是這樣的:

exec sp_executesql n'

update websitechanellistpage set status=0 where id in ((@ilist1,@ilist2))

',n'

@ilist1 int,@ilist2 int

',@ilist1

=1,@ilist2

=2

我們不難發現生成的語句中多了一層括號,於是果段修改**:

string updatestring = "update websitechanellistpage set status=

0where id in

@ilist

"; connection.

execute(updatestring,new );

執行成功!問題解決!

條件判斷的優雅寫法

平時在書寫if else if else 條件判斷,當邏輯複雜時,寫完有種半死不活的感覺,也提現不了 水平,那麼,有什麼好方法來將他更優雅的表現呢?下面來看個例子 const clickevent status,identity else if status 2 else if status 3 e...

條件分支寫法的演進

初級程式設計師寫法 switch 條件表示式 中級程式設計師寫法 if 條件表示式1 else if else 高階程式設計師寫法 let handlers 動態設定條件委託控制代碼 function puthandle key,handler 條件呼叫 function exec key,para...

css not的多個條件的寫法

not 偽類選擇器可以篩選不符合表示式的元素 例子table tbody tr not first child not last child td 以上 可以選擇table 中tbody部分非首個 非最後乙個的tr,並設定其子元素td文字樣式居右 這裡面需要注意not的語法格式 單個的not寫法 選...