gpt4 book ai didi

c# - 将 AutoMapper 与 Xamarin Sqlite 一起使用时未找到 ToList 方法

转载 作者:行者123 更新时间:2023-12-02 11:03:35 25 4
gpt4 key购买 nike

我正在尝试将 AutoMapper 的投影方法与 Xamarin Sqlite 一起使用。我的代码如下所示:

var myList = conn.Table<SomeTable>()
.Where(w => w.ForeignKeyId == foreignKeyId)
.AsQueryable()
.ProjectTo<SomeTableDto>()
.ToList();

该代码在 Android 模拟器上运行,但在 iOS 模拟器上失败。 iOS 上的错误是:

System.NotImplementedException: The method or operation is not implemented.

堆栈跟踪的顶部如下。如果需要,我可以提供完整的堆栈跟踪,它很长。

at Microsoft.Scripting.Interpreter.LightCompiler.CompileMemberInitExpression     (System.Linq.Expressions.Expression expr) [0x00000] in     /Users/builder/data/lanes/3539/f37444ae/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LightCompiler.cs:1532  
at Microsoft.Scripting.Interpreter.LightCompiler.CompileNoLabelPush (System.Linq.Expressions.Expression expr) [0x002a7] in /Users/builder/data/lanes/3539/f37444ae/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LightCompiler.cs:1660

未找到的方法是 ToList() 调用。为什么在 iOS 上找不到该方法?

我已经通过执行以下操作解决了该问题,但我很好奇为什么我的初始代码在 iOS 上不起作用。

var someTableList = conn.Table<SomeTable>()
.Where(w => w.ForeignKeyId == foreignKeyId)
.ToList();

var myDtoList = Mapper.Map<List<SomeTableDto>>(someTableList);

我使用的是 AutoMapper 5.1.1、Xamarin Forms 2.3.1 和 Sqlite-net-pcl 1.1.2。

最佳答案

我很确定问题出在 iOS 链接器上。我在以下位置发现了类似的问题:

https://github.com/AutoMapper/AutoMapper/issues/1542

https://github.com/AutoMapper/AutoMapper/issues/686

感谢@Krumelur 为我指明了 iOS 链接器的方向。如果有人能想到其他任何东西,请告诉我。

关于c# - 将 AutoMapper 与 Xamarin Sqlite 一起使用时未找到 ToList 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39476141/

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