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

标签 c# sqlite xamarin.forms automapper

我正在尝试将 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/

相关文章:

python - 如何使用 DetailView 中 PK(主键)字段以外的不同字段进行查询

linq - 如何编写LINQ查询以将多行合并为一行?

c# - Xamarin - Prism : How do I pass the whole ViewModel of the ContentPage to a child ContentView

c# - 不同情况下呈现的 bool 字段

c# - 如何在 C# 应用程序上连接到 sql server

c# - 与巨大的数据流异步

c# - 跨源请求被阻止——使用 Angular 和 ASP.NET Core 构建的应用程序

sql - SQlite按位操作在更新中

带有长文本的 Xamarin.Forms ScrollView

uwp - Xamarin Forms Stacklayout 未填充 UWP 应用中的整个 MasterPage