Help with Join

Posts   
 
    
redsquare
User
Posts: 3
Joined: 16-Apr-2009
# Posted on: 12-May-2009 17:42:18   

Hi,

I have the following schema http://gyazo.com/c1d2c71705f4f59ad8440bbf33440b97.png.

What I need are the Questions.Description for a given list of AgencyID's and also any related CaseQuestions.Answers, some Questions may not have a CaseQuestion entry.

Is this possible in one Fetch or do I need resort to getting all the questions for a given case and then a separate list of answers?

Thanks

rdhatch
User
Posts: 198
Joined: 03-Nov-2007
# Posted on: 12-May-2009 19:00:36   

Yes, this is absolutely possible. This is very easy to do.

To avoid going to the database multiple times, you must Prefetch whatever tables you're looking to use.

It would help to know if you're using Self-Servicing or Adapter, as you fetch slightly differently. I'm using Self-Servicing here.

So, you'll need a PredicateExpression to determine what AgencyIDs you want to filter by:

Imports MyDataObjects.HelperClasses

Dim myFilters as New PredicateExpression
myFilters.Add(AgencyQuestionsFields.AgencyID = 123)

You will also need to use AgencyQuestionsCollection.GetMulti() to perform the fetch. Unless you want to lazy-load (go to the DB every time, NOT recommended)... you will need to specify what Entities to Prefetch during your initial fetch.

Here is an example:


        'Define Prefetches
        Dim myPrefetches As New PrefetchPath(CType(EntityType.AgencyQuestionsEntity, Integer))
        myPrefetches.Add(AgencyQuestionsEntity.PrefetchPathCaseQuestionsCollectionViaQuestions)

        'Define Relations
        Dim myRelations As New RelationCollection
        myRelations.Add(AgencyQuestionsEntity.Relations.QuestionsEntityUsingAgencyId)
        myRelations.Add(QuestionsEntity.Relations.CaseQuestionsEntityUsingQuestionId)

        'Go!
        Dim myAgencyQuestionsCollection As New AgencyQuestionsCollection
        myAgencyQuestionsCollection.GetMulti(myFilters, 0, Nothing, myRelations, myPrefetches)


Hope this helps!

Ryan

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 12-May-2009 20:50:30   

I seem to be saying this quite a lot recently - "what he said..."

Matt.

rdhatch
User
Posts: 198
Joined: 03-Nov-2007
# Posted on: 12-May-2009 20:55:08   

lol

Love 'ya, man wink Gotta help when I can