开发者

NHibernate 3 QueryOver one to many

I have this nhibernate query

        var session = SessionFactory.GetCurrentSession();

        var users = session.QueryOver<User>()
            .Where(u => u.Enabled)
            .WhereRestrictionOn(u=>u.Orders).IsNull
            .Inner.JoinQueryOver<Foo>(a => a.Foos).Where(c => c.Enabled)
            .Inner.JoinQueryOver<Bar>(m => m.Bars).Where(m => m.Enabled)
            .TransformUsing(new DistinctRootEntityResultTransformer())
            .List();

WhereRestrictionOn Orders doesn't work

but I am trying to ensure these users have zero orders but have Foos and Bars

Can anyone help with a way to do it in NHibernate?

Update:

Here is how I changed this so far - seems to work

        var session = SessionFactory.GetCurrentSession();
        User rawUser = null;

        var existing = QueryOver.Of<Order>().Where(x =&g开发者_如何学Got; x.UserID == rawUser.UserID).Select(x=>x.User);

        var users = session.QueryOver<User>(() => rawUser)
            .Where(u => u.Enabled)
            .WithSubquery.WhereNotExists(existing)
            .Inner.JoinQueryOver<Foo>(a => a.Foos).Where(c => c.Enabled)
            .Inner.JoinQueryOver<Bar>(m => m.Bars).Where(m => m.Enabled)
            .TransformUsing(new DistinctRootEntityResultTransformer())
            .List();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜