Results 1 to 2 of 2

Thread: Linq group join not working correctly?

  1. #1

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,388

    Linq group join not working correctly?

    I have 2 IQueryable's ... AllMappedItems and LastAnswers

    They both work fine and only execute one sql statement each to loop through their results.

    Now the issue is when I join them using:

    vb Code:
    1. Dim MappedAnswers = AllMappedItems.GroupJoin(LastAnswers, Function(x) x.AssessmentTemplateID, Function(y) y.AssessmentTemplateID, Function(x, y) New With {.x = x, .y = y})

    A query then gets executed for each record in MappedAnswers???

    each one with a cross join condition like this:

    Code:
    CROSS JOIN [dbo].[PersonAssAssessmentsAnswers] AS [t9]
    WHERE (N'20150506104416290c0c3e5f26f64659' = [t9].[AssessmentTemplateID])
    ... why is this not working as expected?

    ... Also I haven't posted the full example as it's quite complex ... and I thought that performing basic joining on two IQueryable's should just work (as it does elsewhere) ..

    Thanks,
    Kris

  2. #2

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,388

    Re: Linq group join not working correctly?

    Ok... I have played around with it an have reworked it to this:

    vb Code:
    1. Dim PersonMap = CurrentResidents.Join(AllMappedItems, Function(x) True, Function(y) True, Function(x, y) New With {.Person = x, .CarePlanAssessmentMap = y})
    2.         Dim PersonMapAnswers = PersonMap.Join(LastAnswers, Function(x) New With {Key .a = x.CarePlanAssessmentMap.AssessmentTemplateID, Key .b = x.Person.ID}, Function(y) New With {Key .a = y.AssessmentTemplateID, Key .b = y.PersonAssAssessments.PersonID}, Function(x, y) New With {.Person = x.Person, .CarePlanAssessmentMap = x.CarePlanAssessmentMap, .PersonAssAssementAnswers = y})
    3.         Dim PersonMapAnswersCareplan = PersonMapAnswers.GroupJoin(PersonCarePlanAssessments, Function(x) New With {Key .a = x.Person.ID, Key .b = x.CarePlanAssessmentMap.Category, Key .c = x.CarePlanAssessmentMap.AssessmentTemplateID}, Function(y) New With {Key .a = y.PersonID, Key .b = y.Category, Key .c = y.AssessmentTemplateID}, Function(x, y) New With {.Person = x.Person, .CarePlanAssessmentMap = x.CarePlanAssessmentMap, .PersonAssAssementAnswers = x.PersonAssAssementAnswers, .PersonCarePlanAssessments = y})

    Now when I call .ToArray() on PersonMapAnswersCareplan it iterates through multiple linq statements as stated in my previous post... it only does this on PersonMapAnswersCareplan and NOT PersonMap or PersonMapAnswers??

    CurrentResidents, AllMappedItems and LastAnswers are basic IQueryable's with some data filtered.

    EDIT: Just noticed that it only does this if it is a group join and NOT a join???

    Thanks,
    Kris

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width