Tấn*_*ang 5 asp.net linq-to-entities expression-trees c#-7.0 valuetuple
当我尝试编译以下代码时:
var post = iPostService.GetAll().Select(x => (x.Title, x.Author));
Run Code Online (Sandbox Code Playgroud)
我收到编译器错误:“表达式树可能不包含元组文字。”
所以,我也试过这样:
var post = iPostService.GetAll().
Select(x => new ValueTuple<string, string>(x.Title, x.Author))
Run Code Online (Sandbox Code Playgroud)
结果是运行时错误:“无法解析方法Void .ctor(System.String,System.String),因为方法句柄System.ValueTuple`2 [T1,T2]的声明类型是通用的。将声明类型明确提供给GetMethodFromHandle。
我用谷歌搜索找到了解决这个问题的方法,但是没有什么真正的帮助。
任何帮助真的很感激。
谢谢
Tấn*_*ang 13
最后,我发现我的代码有什么问题:
希望它适用于您的代码。
au.*_*.tw 13
它对我有用,先创建一个元组并将其转换为 ValueTuple?
var post = iPostService.GetAll().
Select(x => new Tuple<string, string>(x.Title, x.Author).ToValueTuple())
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1201 次 |
| 最近记录: |