小巧的人插入列表? [英] Dapper insert a list?
本文介绍了小巧的人插入列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要批量插入。 A是ID,B是ID列表。我的插入语句看起来像这样,但这是错误的。我如何重写它才能工作?我能想到的唯一解决方案是在语句外使用foreach循环
I want to do a bulk insert. A is an ID and B is a list of IDs. My insert statement looks like this but it is wrong. How do I rewrite it to work? The only solution I can think of is using a foreach loop outside the statement
.Execute(@"insert into MyTable(a,b) select @a, @b", new {a, b})
推荐答案
尝试以下操作:
var abs = b.Select(id => new { a, b = id });
int numInserted = connection
.Execute(@"insert into MyTable(a,b) VALUES(@a, @b)", abs);
这篇关于小巧的人插入列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文