views:

46

answers:

2

I can't seem to find any god reference on this. I have alot of data in SQL with dates. So I wanted to make a line chart to show this data over time. If I want to show it over a perioud of days then I need to group by days.. But the LOGDATE is the full date.. not the DAY..

So I have this below.. but LINQ doesnt know what 'DayOfYear' property is.. HELP

 var q = from x in dc.ApplicationLogs
                let dt = x.LogDate
                group x by new { dayofyear = dt.Value.DayOfYear } into g
                select new
                {
                    iCount = g.Count(),
                    strDate = g.Key
                };
A: 

Why are you using:

    let dt = x.LogDate
    group x by new { dayofyear = dt.Value.DayOfYear } into g

instead of just:

    group x by x.LogDate.Value.DayOfYear into g

I'm not sure about this, but it's possible using an anonymous object like that in your group by clause is messing up L2S.

tzaman
dayofyear is not supported by Line2Ent. :(
punkouter
This works.. but only for data within ONE month :( var q = from x in dc.ApplicationLogs group x by new { x.LogDate.Value.Day } into g select new { DayDate = g.Key.Day, iCount = g.Count() };
punkouter
How about just fetching all the data into a `List<LogDate>` and then doing the grouping with plain old LINQ-to-Objects?
tzaman
not sure how to do that.. I mean how to mix a linq2ent query with linqtoobjects
punkouter
+1  A: 

You want .Date to get the date part of a DateTime not DayOfyear unless you are deliberately trying to put the same day of the year from each year into the group.

Hightechrider