I am facing an issue with an unsupported feature in the LINQ implementation of NHibernate (it's firing a QueryException
: "could not resolve property: CreatedOn.Date of: Example.Comment").
Given the entity below, I would like to extract statistics by grouping the comments per day and sum up the amount of comments for each day (naturally it has additional properties and correct mapping, written in Fluent NHibernate):
public class Comment
{
public virtual DateTime CreatedOn
{
get;
set;
}
}
My LINQ query looks like below (the query works fine if executed against a LINQ to SQL context).
var commentsPerDay = (from c in session.Linq<Comment>()
group c by new { c.CreatedOn.Date } into g
select new
{
Date = g.Key.Date,
Count = g.Count()
};
The proper solution would be to contribute to the project and fix this issue.
On the other hand, I would love to find out if (LINQ to) NHibernate has an extensibility point, where I could inject this behaviour. I know I could probably create a custom type and mapping a second property to the date part of the creation time, but I'm guessing this wouldn't translate to a query, which would make it too slow.
I have limited access to rewriting the queries, as they still has to work with LINQ to SQL, so I can't use HQL.