Era só criar um alias pra propriedade, mesmo sendo uma lista.
ISession session = NHibernateHelper.OpenSession();
ICriteria query;
DetachedCriteria dcUsuario = DetachedCriteria.For<Modelo.ControleAcesso.CaAdminUsuario>("usuario")
.Add(Restrictions.Eq("Id", usuarioId))
.CreateAlias("usuario.Perfis", "perfis")
.SetProjection(Projections.Distinct(Projections.Property("perfis.Id")));
DetachedCriteria dcPerfis = DetachedCriteria.For<Modelo.ControleAcesso.CaPerfil>("perfil")
.Add(Subqueries.PropertyIn("perfil.Id", dcUsuario))
.CreateAlias("perfil.Areas", "areas")
.SetProjection(Projections.Distinct(Projections.Property("areas.Id")));
query = session.CreateCriteria<Modelo.ControleAcesso.CaArea>("area")
.Add(Subqueries.PropertyIn("area.Id", dcPerfis));
if (areaId != 0)
{
query.Add(Restrictions.Eq("AreaPaiId.Id", areaId));
}
else
{
query.Add(Restrictions.IsNull("AreaPaiId.Id"));
}
query.AddOrder(new Order("Ordem", true));
return query.List<Modelo.ControleAcesso.CaArea>();
SELECT
this_.areaId as areaId6_0_,
this_.Titulo as Titulo6_0_,
this_.TituloCurto as TituloCu3_6_0_,
this_.Codigo as Codigo6_0_,
this_.VisivelNoMenu as VisivelN5_6_0_,
this_.Ordem as Ordem6_0_,
this_.areaPaiId as areaPaiId6_0_,
this_.paginaPadraoEntradaId as paginaPa8_6_0_
FROM CA_Area this_
WHERE
this_.areaPaiId = 11 and
this_.areaId in (
SELECT distinct areas1_.areaId as y0_
FROM CA_Perfil this_0_
inner join
CA_AreaPorPerfil areas3_
on this_0_.perfilId=areas3_.perfilId
inner join CA_Area areas1_
on areas3_.areaId=areas1_.areaId
WHERE this_0_.perfilId in (
SELECT distinct perfis1_.perfilId as y0_
FROM CA_AdminUsuario this_0_0_
inner join CA_PerfilPorUsuario perfis3_
on this_0_0_.adminUsuarioId=perfis3_.adminUsuarioId
inner join CA_Perfil perfis1_
on perfis3_.perfilId=perfis1_.perfilId
WHERE this_0_0_.adminUsuarioId = 1))