0

I have EF Query:

IEnumerable<Account> accounts 
         = (
           from a in dc.Accounts
            join m in dc.GroupMembers on a.AccountID equals m.AccountID
            where m.GroupID == GroupID && m.IsApproved
            select a)
           .Skip((_configuration.NumberOfRecordsInPage * (PageNumber - 1)))
           .Take(_configuration.NumberOfRecordsInPage);

How to write it in fluent nhibernate query with Session.CreateCriteria<>? (My problem is with Join)

Preet Sangha
  • 64,563
  • 18
  • 145
  • 216
Shlomi Levi
  • 3,114
  • 1
  • 23
  • 35

1 Answers1

1

There's a good answer by phill here - NHibernate QueryOver with ManytoMany which has an example of join with QueryOver

var result = Session.QueryOver<Product>()
                        .Right.JoinQueryOver<Category>(x => x.Categories)
                        .Where(c => c.Id == categoryId)
                        .List();

He also describes how to use linq with query over:

var users = from u in session.Query<Users>()
        where u.UserName == "Abcd"
        && u.Password == "123456"
        select u;

So applying the above examples to your query somethign like this might work:

(from a in session.Query<Account>()
                                     join m in session.Query<GroupMember>() on a.AccountID equals m.AccountID
                                     where m.GroupID == GroupID && m.IsApproved
                                     select a).Skip((_configuration.NumberOfRecordsInPage * (PageNumber - 1)))
                                     .Take(_configuration.NumberOfRecordsInPage);

However, to help better understand the issue you are having, could you post what you have attemtpted?

Community
  • 1
  • 1
jflood.net
  • 2,446
  • 2
  • 21
  • 19