Hi there,
With your example I was able to get this to work...
PrefetchPath2 path2 = new PrefetchPath2((int)EntityType.MessageInternalRecipientEntity);
IPrefetchPathElement2 prefetchPathElement = MessageInternalRecipientEntity.PrefetchPathMessage;
prefetchPathElement.SubPath.Add(MessageEntity.PrefetchPathMessageInternalRecipient).SubPath.Add( MessageInternalRecipientEntity.PrefetchPathUser);
prefetchPathElement.SubPath.Add(MessageEntity.PrefetchPathMessageExternalRecipient);
prefetchPathElement.SubPath.Add(MessageEntity.PrefetchPathUser);
path2.Add(prefetchPathElement);
path2.Add(MessageInternalRecipientEntity.PrefetchPathUser);
So here is a better description of the tables....
Users
UserID PK
Messages
MessageID PK
UserID FK (Sender)
Internal Recipients
InternalRecipientID PK
MessageID FK
UserID FK
DateViewed
ExternalRecipients
ExternalRecipientID PK
MessageID FK
EmailAddress
Now, when I'm showing a user's inbox, I can't link off it to the message detail page using the message's PK because a user may have been sent the same message twice. Once, say, as the primary recipient and then also as a Cc.
So at the message detail page, when I need to update the message's DateViewed column for the user, I need to know the InternalRecipientID in order to update the right one.
So I'm loading the Internal Recipient entity and then prefetching the message and related data. Trouble with the code above is that its getting the same Internal Recipient entity twice. Once for the main fetch and once for the prefetch.
I suppose I could filter it out from the prefetch or maybe do two different fetches - one for the recipient entity and then look up the message seperately. Or I could just pass the messageID along with the InternalRecipientID from the inbox. That's probably simpler.
Ian.