dapper docsによると、次のように書くことができます
connection.Execute(@"insert into MyTable(colA, colB) values (@a, @b)",
new[] { new { a=1, b=1 }, new { a=2, b=2 }, new { a=3, b=3 } }
)
使ってみた
conn.Execute(
@"
insert into RelRoleUser ( RoleID, UserID )
values( @roleID, @userID )",
userroleList.Select(r => new { roleID = r.roleID, userID = r.userID }).ToArray(),
null, null, null);
ただし 、Dapper コードで例外「DynamicMethod の型所有者が無効です」が発生する
private static Action<IDbCommand, object> CreateParamInfoGenerator(Type type)
{
var dm = new DynamicMethod(string.Format("ParamInfo{0}", Guid.NewGuid()), null, new[] { typeof(IDbCommand), typeof(object) }, type, true);
...
あまりにも巧妙なコードを書こうとしているのですか、それとも何か他のことを誤解していますか? バグに遭遇しましたか?
Win7 で Dotnet3.5 を実行しています。