views:

885

answers:

3

Take this query as an example:

select * from publisher 
where id not in (
    select publisher_id from record 
    where year = 2008 and month = 4
)

Can anyone help me on how I could build and run this query using NHibernate? Assume that I have 2 classes: Publisher and Record.

Thanks

+2  A: 

Try this:

DetachedCriteria c = DetachedCriteria.For<Record>()
    .SetProjection(Projections.Property("Publisher"))
    .Add(Restrictions.Eq("Year", 2008))
    .Add(Restrictions.Eq("Month", 4));
session.CreateCriteria(typeof(Publisher))
    .Add(Subqueries.PropertyNotIn("Id", c))
    .List();
Stuart Childs
A: 

this works, thanks

raulucian
A: 

select count(*) from employee where not exists (select * from salary where employee_id = employee.id)

Can any one write Query for this please.

vardhan
@vardhan On StackOverflow each "thread" is all about 1 question. Your best bet for an answer to this is to start a new question of your own. Click the "ask question" button at the top right. :)
Mike