I'm trying to group entities by their date by month : the query works, but does not group objects by the computed date, but by the original date.
Sample below : I was expecting only one group with this code, but I'm getting 50 groups.
Model
[HierarchyRoot]
public class MyEntity : Entity
{
[Field, Key]
public int Id { get; private set; }
[Field]
public DateTime Date { get; set; }
}
Object creation
for (int i = 0; i < 50; i++)
{
var myEntity = new MyEntity(session)
{
Date = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 12, i, 0)
};
}
Query
var query = from i in session.Query.All<MyEntity>()
let startMonth = new DateTime(i.Date.Year, i.Date.Month, 1)
group i by startMonth into g
select g;
Console.WriteLine(query.Count() + " groups by date");
Could you investigate this behavior?
asked
Oct 25 '11 at 04:17
olorin
358●87●87●92
Will be checked.