I have two entities which are:
User
{
UserGuid,
Address,
.
.
.
EmailCount // This is not a column in the database,
// I just wanna get the count number from the UserEmail table
// and map the value to this property
}
UserEmail
{
UserGuid,
Timestamp
}
The issue is how can I get the email count with a sub query in NHibernate?
By far I have this, but it does not work. Any idea?
User userEntity = null;
var subQuery = QueryOver.Of<UserEmail>()
.Where(ue => ue.UserGuid == userEntity.UserGuid)
.ToRowCountQuery();
return _session.StatefulSession.QueryOver(() => userEntity)
.WithSubquery.WhereValue("EmailCount").Eq(subQuery)
.List();