I have the following line of code:
group p by new DateTime((p.DateTime.Value.Ticks / interval.Ticks) * interval.Ticks).TimeOfDay
This works great in LINQ-to-Objects but it will not work in LINQ-to-Entities. I have two quetsions:
-
Why does it work? I don’t understand how dividing the time by an interval and then multiplying it by that same interval magically converts my 12:37 to 12:30. My basic experience with math says that (A/B)*B = A. (Cleared up by @spencer in comments. Much thanks!)
-
How can I reformat this line to work in LINQ-to-Entities?
The DateTime methods you are using can’t be translated by l2e. Consider using the
EntityFunctionsclass for supported time operations.See here for more details.
For instance, say your interval were 60 seconds, I’m guessing you might do something like: