Dapper: Execute a command multiple times and linq and ToArray

孤人 提交于 2020-01-11 11:18:55

问题


According to the dapper docs one can write

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 } }
    )

I tried using

conn.Execute(
    @"
    insert into RelRoleUser ( RoleID, UserID )
    values( @roleID, @userID )",
    userroleList.Select(r => new { roleID = r.roleID, userID = r.userID }).ToArray(),
    null, null, null);

But get an exception "Invalid type owner for DynamicMethod" in Dapper code

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);
    ...

Am I trying to write too clever code or have I misunderstood something else? Stumbled upon a bug?

I am running Dotnet3.5 on Win7.

来源:https://stackoverflow.com/questions/8705325/dapper-execute-a-command-multiple-times-and-linq-and-toarray

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!