2016-03-02 68 views
1

我想在nhibernate中做一個查詢,我遇到了一個問題。Nhibernate - 查詢空過時檢查別名給對象空參考

我想要接收所有具有模式「報告」的事件報告(沒有事件的報告)可爲空)

所以我嘗試:

Incident inc = null; 

Session.QueryOver<Report>() 
    .Left.JoinAlias(r => r.Incident,() => inc) 
    .Where(new Disjunction() 
     .Add(Restriction.On(() => inc).IsNull) 
     .Add(() => inc.Type == "Violence")); 

,我也得到:

對象refernces不設置到對象的實例。

回答

1

試試這個:

Session.QueryOver<Report>().Left.JoinAlias(r => r.Incident,() => inc) 
    .Where(
     Restrictions.Disjunction() 
     .Add(Restrictions.On<Report>(r => r.Incident).IsNull) 
     .Add(Restrictions.Eq(Projections.Property(() => inc.Type), "Violence")) 
    );