【问题标题】:ToList Method not Found when using AutoMapper with Xamarin Sqlite将 AutoMapper 与 Xamarin Sqlite 一起使用时找不到 ToList 方法
【发布时间】:2016-09-13 17:48:59
【问题描述】:

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

【问题讨论】:

  • 您是否将 Nuget 包添加到您的 Forms PCL iOS 项目中?两者都需要它们。
  • 我只添加了 AutoMapper 我的 PCL 项目,它没有添加到 droid 或 iOS 项目中。当我将 AutoMapper 添加到 iOS 时,列出了 30 多个依赖项,它还需要安装,所以我很犹豫要不要这样做。我上面列出的示例代码都在我的 PCL 项目中。
  • 有问题。必须将包添加到本机项目中。我不知道如何以及为什么会引入 30 个依赖项。
  • @Krumelur,我的 PCL 项目中有其他使用 AutoMapper 的数据库方法,它们可以工作。只有在 iOS 中给我带来问题的只是 ProjectTo 和 ToList。我的问题中的代码在 Andriod 上运行良好,我没有在 Andorid 项目中包含 AutoMapper。
  • 嗯,你可以试一试,对吧?它可能是在 iOS 上剥离内容的链接器。如果你拒绝尝试的事情,你永远不会知道。

标签: c# sqlite xamarin.forms automapper


【解决方案1】:

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

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多