Using the PathEdge works...but it didn't yield the results I need. It turns out I had the where clause in the wrong place. The following solved it.
var q = (from t in Context.BankTransaction where t.Activities.Contains(new ActivityEntity(activityID)) select t)
.WithPath(transPath => transPath
.Prefetch<ActivityEntity>(a => a.Activities)));
I should let you know of a bug I found, though.
I have the following entities:
BankTransaction
Activity
Contact
BankTransaction has many Activities
BankTransaction has a Contact
Activity has a Contact
Contact is a supertype (subtype Individual, Business).
Activity is a supertype.
When I use the following query:
var q = (from trans in Context.BankTransaction
where trans.Activities.Contains(new ActivityEntity(activityID))
select trans)
.WithPath(transPath => transPath
.Prefetch<ActivityEntity>(a => a.Activities)
.SubPath(activityPath => activityPath
.Prefetch(c => c.Contact)))
.Prefetch(tc => tc.Contact)
.Prefetch(tb => tb.TransactionStatus));
The retrieved BankTransaction's Contact is accurate, and the Activities collection properly contains 1 ActivityEntity instance. However, the ActivityEntity's Contact is, incorrectly, that of the BankTransaction. In the database the Activity is linked to a different contact, and the traced SQL query shows it returning the correct query...but when the ORM returns the objects, it is the wrong Contact.
Now, if I use the same query, (resulting in the same SQL) but change the order of the BankTransaction Contact path, to be like so:
var q = (from trans in Context.BankTransaction
where trans.Activities.Contains(new ActivityEntity(activityID))
select trans)
.WithPath(transPath => transPath
.Prefetch(tc => tc.Contact)
.Prefetch<ActivityEntity>(a => a.Activities)
.SubPath(activityPath => activityPath
.Prefetch(c => c.Contact)))
.Prefetch(ts=>ts.TransactionStatus));
then the proper Contact for Activity is populated.
I've also confirmed this problem when using just standard, non-linq API objects, like PrefetchPathElement2.