How to create DetachedCriteria criteria for a field in a join table?

0

First time I move with this and I'm having trouble setting up the query properly.

Here is my code done the wrong way, so it is not obeying the conditions:

public IList<Ficha> ObterFichas()
{        
    DetachedCriteria criteria = DetachedCriteria.For<Ficha>();
    criteria.SetMaxResults(1);

    DetachedCriteria criteriaExportacao = DetachedCriteria.For<Exportacao>();       
    criteriaExportacao.CreateAlias("exportacao","e", NHibernate.SqlCommand.JoinType.LeftOuterJoin).Add(Restrictions.Eq("exportacao.Exportado", null)).Add(Property.ForName("e.Exportado").In(criteria));

    var ok = DomainService.FichaRepository().LoadAll(criteria);

    return ok;
}

The first record is returned, but the first record does not have the Exported field as null.

I have the tab and the export table in my bank. It is a relationship mapped from 1 to 1. In the tab and the export table I have IdFic as PK and PK / FK respectively.

Given this information what I want to do is to set up a query that brings only 1 result row with the left join between table tab and export table. That should only bring null results as I tried to do in the condition of my code, but that is wrong.

    
asked by anonymous 07.05.2014 / 19:38

1 answer

0

I got it, it looked like this:

public IList<Ficha> ObterFichas()
{        
    DetachedCriteria criteria = DetachedCriteria.For<Ficha>();
    criteria.SetMaxResults(1);

    criteria.CreateAlias("exportacao", "e",NHibernate.SqlCommand.JoinType.LeftOuterJoin).Add(Restrictions.IsNull("e.Exportado"));

    var ok = DomainService.FichaRepository().LoadAll(criteria);

    return ok;
}
    
07.05.2014 / 20:03