gpt4 book ai didi

c# - Dapper 抛出 "Invalid type owner for DynamicMethod."

转载 作者:可可西里 更新时间:2023-11-01 07:55:23 38 4
gpt4 key购买 nike

所以我正在尝试使用 Dapper.net,而且我很喜欢它。我不喜欢的是当我尝试批量插入实体时抛出以下错误:

DynamicMethod 的类型所有者无效。

at 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) at System.Reflection.Emit.DynamicMethod..ctor(String name, Type returnType, Type[] parameterTypes, Type owner, Boolean skipVisibility) at Dapper.SqlMapper.CreateParamInfoGenerator(Identity identity, Boolean checkForDuplicates, Boolean removeUnused, IList1 literals) in
D:\Dev\dapper-dot-net\Dapper NET40\SqlMapper.cs:line 3033 at
Dapper.SqlMapper.GetCacheInfo(Identity identity, Object
exampleParameters, Boolean addToCache) in D:\Dev\dapper-dot-net\Dapper
NET40\SqlMapper.cs:line 2138 at
Dapper.SqlMapper.<QueryImpl>d__61
1.MoveNext() in D:\Dev\dapper-dot-net\Dapper NET40\SqlMapper.cs:line 1578 at System.Collections.Generic.List1..ctor(IEnumerable1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source) at
Dapper.SqlMapper.Query[T](IDbConnection cnn, String sql, Object param,
IDbTransaction transaction, Boolean buffered, Nullable
1 commandTimeout, Nullable1 commandType) in
D:\Dev\dapper-dot-net\Dapper NET40\SqlMapper.cs:line 1479 at
Dapper.SqlMapper.Query(IDbConnection cnn, String sql, Object param,
IDbTransaction transaction, Boolean buffered, Nullable
1 commandTimeout, Nullable1 commandType) in
D:\Dev\dapper-dot-net\Dapper NET40\SqlMapper.cs:line 1418 at
NinjaEvaluation.Data.Database.DapperWrapper.<>c__DisplayClass4
1.b__3(SqlConnection sqlConnection, SqlTransaction transaction) in c:\Projects\InHouse\ninjaevaluation\NinjaEvaluation\NinjaEvaluation.Data\Database\DapperWrapper.cs:line 52 at NinjaEvaluation.Data.Database.DapperWrapper.Invoke(Action`2 action) in c:\Projects\InHouse\ninjaevaluation\NinjaEvaluation\NinjaEvaluation.Data\Database\DapperWrapper.cs:line 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)

我找到了 the following SO-thread由遇到同样问题的人开始,但问题似乎是 .NET 版本 (3.5),但我运行的是 .NET 4.5,我无法弄清楚问题是什么。

有什么建议吗?

最佳答案

我在使用接口(interface)而不是类时遇到了这个错误:

Query<MyObject>工作,同时 Query<IMyObject>没有

关于c# - Dapper 抛出 "Invalid type owner for DynamicMethod.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30435185/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com