无法将源类型转换为System.Nullable <double>

时间:2016-03-08 06:40:04

标签: c# angularjs

这是我的剧本:

public PlainBrgDataSummaryComplete SummaryComputationPerTransSQLite(long    ProgramID)
{
    PlainBrgDataSummaryComplete result = new  PlainBrgDataSummaryComplete();
    DataSet dataSet = GetPlainBrgDataSQLite(ProgramID);

    var abcde  = dataSet.Tables["dataBridge"]
        .AsEnumerable()
        //.Where(a => Convert.ToDateTime(a["reportingDate"].ToString()) >= startOfWeek1 && Convert.ToDateTime(a["reportingDate"].ToString()) < endOfWeek1.AddDays(1))
       .GroupBy(a => 1)
        .Select(d =>
            new PlainBrgDataSummaryTrans
            {
                transactionWk6 = d.Sum(a => a.Field<double?>("TranCount"))

            }
        ).FirstOrDefault();

    result.totaltransaction = new PlainBrgDataSummaryTrans
    {
        transactionWk6 = abcde;
    };

    return result;
}

我收到错误 - 无法将源类型转换为System.Nullable<double>。特别是在transactionWk6 = abcde;

部分

2 个答案:

答案 0 :(得分:1)

abcde已经是PlainBrgDataSummaryTrans类型,因为您正在向其投射select语句。

尝试使用它:

result.totaltransaction = abcde;
return result;

答案 1 :(得分:0)

Mihail Stancescu应该解决这个问题。但是考虑到你的返回类型,你不需要额外的任务。你可以改变下面的代码

public PlainBrgDataSummaryComplete SummaryComputationPerTransSQLite(long    ProgramID)
{
DataSet dataSet = GetPlainBrgDataSQLite(ProgramID);

return dataSet.Tables["dataBridge"]
    .AsEnumerable()
    //.Where(a => Convert.ToDateTime(a["reportingDate"].ToString()) >= startOfWeek1 && Convert.ToDateTime(a["reportingDate"].ToString()) < endOfWeek1.AddDays(1))
   .GroupBy(a => 1)
    .Select(d =>
        new PlainBrgDataSummaryTrans
        {
            transactionWk6 = d.Sum(a => a.Field<double?>("TranCount"))

        }
    ).FirstOrDefault();

}