0

Ok so I have the following relationships:

Bulletin < BulletinEmailLog < BulletinEmailLogRecipient - Contact - Entity

Where the "<" stands for 1 to many and the "-" is one to one.

And here is the code:

BulletinEmailLog BulletinEmailLogs = null;
        BulletinEmailRecipient EmailRecipients = null;
        Contact Contact = null;
        Entity Entity = null;
        var pastBulletin = NHibernateSession.Current.QueryOver<Bulletin>()
                        .Where(x => x.Id == bulletinID)
                        .Fetch(x => x.BulletinEmailLogs).Eager
                        .JoinAlias(x => x.BulletinEmailLogs, () => BulletinEmailLogs, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                        .JoinAlias(() => BulletinEmailLogs.Recipients, () => EmailRecipients, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                        .JoinAlias(() => EmailRecipients.Contact, () => Contact, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                        .JoinAlias(() => Contact.Entity, () => Entity, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                        .Future<Bulletin>();

Here I try to use one database query to grab all of the necessary information. The problem , is that later I try to loop through the BulletinEmailLogs but I see a call to the database. I would like to be able to add eager loading statements within the preceding code in order to do later searches using memory. Is that possible?

  • 1
    When you see the calls to the database, are you sure it's populating the "BulletinEmailLogs", and not other parts which aren't eagerly loaded? (eg It could be populating the BulletinEmailLogRecipients) – Andrew Shepherd Feb 12 '13 at 03:46

1 Answers1

0

Thank you for your suggestion. I removed the eager load statement and found that only one call to the database was being made. Now I have a different concern/problem. There are other tables referenced in the query that I'm not familiar with. I'm new to the code so it may just be that I hadn't looked up the relationships properly. But anyway , thanks.