【发布时间】:2018-06-16 17:02:30
【问题描述】:
当我试图编译以下代码时:
var post = iPostService.GetAll().Select(x => (x.Title, x.Author));
我收到编译器错误:“表达式树可能不包含元组文字。”
所以我也试过这个:
var post = iPostService.GetAll().
Select(x => new ValueTuple<string, string>(x.Title, x.Author))
结果是运行时错误:'Cannot resolve method Void .ctor(System.String, System.String) 因为方法句柄 System.ValueTuple`2[T1,T2] 的声明类型是通用的。向 GetMethodFromHandle 显式提供声明类型。'
我搜索了这个问题的解决方案,但没有任何帮助。
非常感谢任何帮助。
谢谢
【问题讨论】:
-
原问题由Expression trees support for tuples. #12897跟踪。但看起来你不能在编译时表达式中以任何方式使用
ValueTuple,所以恐怕目前没有解决方案/解决方法。
标签: asp.net linq-to-entities expression-trees c#-7.0 valuetuple