m:n Prefetch Path question.

Posts   
 
    
Sam avatar
Sam
User
Posts: 95
Joined: 30-Jun-2004
# Posted on: 02-Mar-2006 16:59:27   

I have a business layer method that is supposed to fetch all contacts and contact addresses (m:n collection) for a particular sales subject it looks like this


        EntityCollection IContactManager.GetContactsForSalesSubject(SalesSubjectEntity salesSubject)
        {
            PrefetchPath2 path = new PrefetchPath2((int)EntityType.SalesSubjectEntity);
            path.Add(SalesSubjectEntity.PrefetchPathSalesSubjectContact ).SubPath.Add(SalesSubjectContactEntity.PrefetchPathContact).SubPath.Add( ContactEntity.PrefetchPathContactAddress).SubPath.Add(ContactAddressEntity.PrefetchPathAddress);
//helper method
            base.FetchEntityCollection(salesSubject.SalesSubjectContact, null, salesSubject.GetRelationInfoSalesSubjectContact(), path);
            return salesSubject.SalesSubjectContact;
        }

for some reason salesSubject.SalesSubjectContact is popultaed but (example salesSubject.SalesSubjectContact.Count is 3) but salesSubject.SalesSubjectContact[0].Contact is null. What am I doing wrong here. This worked earlier where I was using a shared context but seems broken now that it has been removed.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 03-Mar-2006 07:26:11   

First of all you are fetching SalesSubjectContact Collection, then your PrefetchPath should start with it, not with SalesSubject, as follows:

EntityCollection IContactManager.GetContactsForSalesSubject(SalesSubjectEntity salesSubject)
        {
            PrefetchPath2 path = new PrefetchPath2((int)EntityType.SalesSubjectContactEntity);
            path.Add(SalesSubjectContactEntity.PrefetchPathContact ).SubPath.Add(ContactEntity.PrefetchPathContactAddress).SubPath.Add( ContactAddressEntity.PrefetchPathAddress);
//helper method
            base.FetchEntityCollection(salesSubject.SalesSubjectContact, null, salesSubject.GetRelationInfoSalesSubjectContact(), path);
            return salesSubject.SalesSubjectContact;
        }

If this still returns the same results, then try to examine the generated SQL Queries and run them in your Database Query execution program, like Query Analayzer, to examine the results returned.

Sam avatar
Sam
User
Posts: 95
Joined: 30-Jun-2004
# Posted on: 03-Mar-2006 23:42:47   

Boooya....That was it...Thanks!