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?
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.