【问题标题】:Error with Select statement in Lambda expressionLambda 表达式中的 Select 语句出错
【发布时间】:2016-12-19 21:34:55
【问题描述】:

我有以下代码:

getAllResult.GroupBy(g => g.OriginatingTransactionID)
.Select(r => 
{
    usp_GetAll_Result getAllResult1 = r.Select(x => x).FirstOrDefault();
    Bundle bundle = new Bundle
    {
        BundleName = getAllResult1.BundleName,
        BundleStatusCode = getAllResult1.BundleStatusCode,
        BundleStatusReasonCode = getAllResult1.BundleStatusReasonCode
    };
}).ToList();

编译时出现错误:

方法的类型参数 'System.Linq.Enumerable.Select(System.Collections.Generic.IEnumerable, System.Func)' 不能从用法中推断出来。尝试 明确指定类型参数。

【问题讨论】:

  • Select 中的函数必须返回一个值,Select 方法的返回类型将从该返回值中推断出来。

标签: c# linq


【解决方案1】:

.Select() 返回一个值。目前你没有从你的表达中返回任何东西。

只需退回您的捆绑包。

Bundle bundle = new Bundle
                {
                    BundleName = getAllResult1.BundleName,
                    BundleStatusCode = getAllResult1.BundleStatusCode,
                    BundleStatusReasonCode = getAllResult1.BundleStatusReasonCode
                };

return bundle;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-19
    • 2015-12-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多