0

I need to set LINQ query results to double array. After executing the next statement I get anonymous types, and I can't convert the Array to double type. How can I do that? Code:

var rls = context.Test
    .GroupBy(cont => new
    {
        wd = System.Data.Objects.SqlClient.SqlFunctions.DatePart("weekday", cont.datetime),
        hh = System.Data.Objects.SqlClient.SqlFunctions.DatePart("hour", cont.datetime)
    })
    .Select(rs => new
        {
            rs.Key.wd,
            rs.Key.hh,
            count = rs.Count()
        }).Where(rs => rs.hh != null & rs.wd !=null).ToArray();

Thanks in advance.

4

1 回答 1

1

问题是这个Select方法返回一个匿名类型,然后这成为查询的返回类型

.Select(rs => new
    {
        rs.Key.wd,
        rs.Key.hh,
        count = rs.Count()
    })

为了返回另一种类型,您将需要另一个Select语句来创建要在管道中返回的新值。问题提到了获得double回报,但不清楚你想成为哪个double价值。如果您只想返回说wd参数,那么您可以执行以下操作

.Where(rs => rs.hh != null & rs.wd !=null)
.Select(x => x.wd)
.ToArray();
于 2013-08-22T16:21:03.667 回答