NHiberante is really powerful. One of overloads of the method you used CreateAlias
looks like this:
public DetachedCriteria CreateAlias(string associationPath
, string alias
, JoinType joinType
, ICriterion withClause);
The most interesting part in this case is the last withClause. This is in fact definition of conditions to be place directly into the JOIN clause
So what you should do is somehting like this:
var restriction = Restrictions.Disjunction()
.Add(Restrictions.Eq("CRMContactId", crmContactId))
.Add(Restrictions.IsNull("CRMContactId")));
And having this just adjust the defintion of the DetachedCriteria:
var criteria = DetachedCriteria.For<ExtraRiskQuestionAnswer>("extraRiskQuestionAnswer")
.CreateAlias("RefRiskQuestion"
, "refRiskQuestion"
, JoinType.RightOuterJoin
, restriction ) // HERE we go, that will be placed where you expected
And now you should have what you need. Other words, any additional restrictions for JOIN clause must be placed into WithClause .