Fluent Nhibernate Not In Case Statement

579 Views Asked by At

I'm trying to code "not in" statement in FN, but don't really know what's the best way to make it. Here is some sql statement:

 select * from T1
 where T1. id not  in
 (
     select distinct T2.fkeyID from T2
 )

Should I create mappings with references one-to-many and use a property check? Or is there any other way, e.g. somehow to write QueryOver for resolving issue? Thanks.

1

There are 1 best solutions below

0
On BEST ANSWER
var subquery = QueryOver.Of<T2>()
    .Select(Projections.Distinct(Projections.Property("referencedT1.id")))

var results = session.QueryOver<T1>()
    .WithSubquery.WhereProperty(t1 => t1.Id).NotIn(subquery)
    .List();