The way with QueryOver
would be:
TransactionEntitytrans = null;
TransactionDetails details = null;
var results = session.QueryOver<TransactionEntity>(() => trans)
.JoinQueryOver(() => trans.Details, () => details, JoinType.InnerJoin
, Restrictions.EqProperty(
Projections.Property<TransactionEntity>(_ => trans.DatePerformed ),
Projections.Cast(
NHibernate.NHibernateUtil.Date,
Projections.Property<Occupation>(_ => details.datetimedetails ))
)
)
.List<TransactionEntity>();
What we are effectively doing is the usage of the forth parameter of the .JoinQueryOver()
. This parameter is a restriction (ICriterion withClause
) and is added to the JOIN with AND operator
INNER JOIN TransactionDetails details
ON trans.ID = details.TransactonID
// here is injected the with clause
AND trans.DatePerformed = CAST(details.datetimedetails AS DATE)
And in this withClause we are just creating restriction with a small trick Restrictions.EqProperty()
, because this takes to projections
EqProperty(IProjection lshProjection, IProjection rshProjection)
(so we do not compare two properties but some other projections). And then we just use CAST to get the required result