我正在尝试使用Dapper.net,并且我喜欢它。但是,当我尝试批量插入实体时,我遇到了以下错误:
DynamicMethod的类型所有者无效。
在System.Reflection.Emit.DynamicMethod.Init(String name,MethodAttributes attributes,CallingConventions callingConvention,Type returnType,Type [] signature,Type owner,Module m,Boolean skipVisibility,Boolean transparentMethod,StackCrawlMark& stackMark)中 在System.Reflection.Emit.DynamicMethod..ctor(String name,Type returnType,Type [] parameterTypes,Type owner,Boolean skipVisibility)中 在Dapper.SqlMapper.CreateParamInfoGenerator(Identity identity,Boolean checkForDuplicates,Boolean removeUnused,IList<code>1 literals)中,在D:\ Dev \ dapper-dot-net \ Dapper NET40 \ SqlMapper.cs:第3033行 在Dapper.SqlMapper.GetCacheInfo(Identity identity,Object exampleParameters,Boolean addToCache)中,在D:\ Dev \ dapper-dot-net \ Dapper NET40 \ SqlMapper.cs:第2138行 在Dapper.SqlMapper.<QueryImpl>d__61<T> .MoveNext()中,在D:\ Dev \ dapper-dot-net \ Dapper NET40 \ SqlMapper.cs:第1578行 在System.Collections.Generic.List<code>1 ..ctor(IEnumerable<code>1 collection)中 在System.Linq.Enumerable.ToList [TSource](IEnumerable<code>1 source)中 在Dapper.SqlMapper.Query [T](IDbConnection cnn,String sql,Object param,IDbTransaction transaction,Boolean buffered,Nullable<code>1 commandTimeout,Nullable<code>1 commandType)中,在D:\ Dev \ dapper-dot-net \ Dapper NET40 \ SqlMapper.cs:第1479行 在Dapper.SqlMapper.Query(IDbConnection cnn,String sql,Object param,IDbTransaction transaction,Boolean buffered,Nullable<code>1 commandTimeout,Nullable<code>1 commandType)中,在D:\ Dev \ dapper-dot-net \ Dapper NET40 \ SqlMapper.cs:第1418行 在NinjaEvaluation.Data.Database.DapperWrapper.<>c__DisplayClass4`1.b__3(SqlConnection sqlConnection,SqlTransaction transaction)中,在c:\ Projects \ InHouse \ ninjaevaluation \ NinjaEvaluation \ NinjaEvaluation.Data \ Database \ DapperWrapper.cs:第52行 在NinjaEvaluation.Data.Database.DapperWrapper.Invoke(Action`2 action)中,在c:\ Projects \ InHouse \ ninjaevaluation \ NinjaEvaluation \ NinjaEvaluation.Data \ Database \ DapperWrapper.cs:第68行
当我像这样运行查询时,即使在完全正常的情况下,也会发生这种情况:
string sql = @" INSERT INTO XXX
(XXXId, AnotherId, ThirdId, Value, Comment)
VALUES
(@XXXId, @AnotherId, @ThirdId, @Value, @Comment)";
var parameters = command
.MyModels
.Select(model => new
{
XXXId= model.XXXId,
AnotherId= model.AnotherId,
ThirdId= model.ThirdId,
Value = model.Value,
Comment = model.Comment
})
.ToArray();
...
sqlConnection.Query(sql, parameters, commandType: commandType, transaction: transaction)
我发现有人遇到了同样的问题,他们在这个SO线程中讨论。但是那里的问题似乎是 .NET 版本(3.5),而我正在使用 .NET 4.5,我无法找出问题所在。你有什么建议吗?