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's gravatar image

olorin
356838489

Will be checked.

(Oct 25 '11 at 05:50) Dmitri Maximov Dmitri%20Maximov's gravatar image
Be the first one to answer this question!
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

powered by OSQA