Group Join Linq problem

5 posts, 0 answers
  1. MNP
    MNP avatar
    40 posts
    Member since:
    Apr 2008

    Posted 03 Feb 2010 Link to this post

    Trying to do a basic join with the query below

          Dim Scope As IObjectScope = PartnerSummary.ObjectScopeProvider1.GetNewObjectScope() 
     
     
          Dim result1 As IObjectScopeQuery(Of PartnerSummary.PartnerInitiative) = From pInit In Scope.Extent(Of PartnerSummary.PartnerInitiative)() _ 
                      Where pInit.PartnerSummaryID = mPartnerSummaryID _ 
                      Select pInit 
     
          Dim initiatives As IObjectScopeQuery(Of PartnerSummary.Initiative) = From I In Scope.Extent(Of PartnerSummary.Initiative)() Select I 
     
         Dim tmp1 As IObjectScopeQuery(Of PartnerSummary.Initiative) = initiatives 
          Dim tmp2 As IObjectScopeQuery(Of PartnerSummary.PartnerInitiative) = result1 
     
          Dim result = From Inits In tmp1 _ 
                      Group Join pInit In tmp2 _ 
                      On Inits.InitiativeID Equals pInit.Id _ 
                      Into OV = Group _ 
                      From pInit2 In OV.DefaultIfEmpty() _ 
         Select New PartnerSummary.PartnerInitiativeQuestions With { _ 
             .InitiativeID = Inits.InitiativeID, _ 
             .Description = Inits.Description, _ 
             .Value = If(OV Is Nothing, 0, pInit2.Value), _ 
             .Comment = If(OV Is Nothing"", pInit2.Comment), _ 
             .PartnerIniativesID = If(OV Is Nothing, 0, pInit2.PartnerIntiativesID)} 

    When result.ToList() is called to try and bind to a repeater, ORM comes back with a "The Last accepted query piece is not from the this query"

    If I switch the IObjectScopeQuery to just a simple List

          Dim Scope As IObjectScope = PartnerSummary.ObjectScopeProvider1.GetNewObjectScope() 
     
     
          Dim result1 As IObjectScopeQuery(Of PartnerSummary.PartnerInitiative) = From pInit In Scope.Extent(Of PartnerSummary.PartnerInitiative)() _ 
                      Where pInit.PartnerSummaryID = mPartnerSummaryID _ 
                      Select pInit 
     
          Dim initiatives As IObjectScopeQuery(Of PartnerSummary.Initiative) = From I In Scope.Extent(Of PartnerSummary.Initiative)() Select I 
     
          Dim tmp1 As List(Of PartnerSummary.Initiative) = initiatives.ToList() 
          Dim tmp2 As List(Of PartnerSummary.PartnerInitiative) = result1.ToList 
     
          Dim result = From Inits In tmp1 _ 
                      Group Join pInit In tmp2 _ 
                      On Inits.InitiativeID Equals pInit.Id _ 
                      Into OV = Group _ 
                      From pInit2 In OV.DefaultIfEmpty() _ 
         Select New PartnerSummary.PartnerInitiativeQuestions With { _ 
             .InitiativeID = Inits.InitiativeID, _ 
             .Description = Inits.Description, _ 
             .Value = If(OV Is Nothing, 0, pInit2.Value), _ 
             .Comment = If(OV Is Nothing"", pInit2.Comment), _ 
             .PartnerIniativesID = If(OV Is Nothing, 0, pInit2.PartnerIntiativesID)} 

    I get an object reference not set to a reference.

    I'm guessing the ORM is returning the similar error.
    Any help would be appreciated.

    Thanks

    -Matt
  2. MNP
    MNP avatar
    40 posts
    Member since:
    Apr 2008

    Posted 03 Feb 2010 Link to this post

    Got it to work by using the following

      Dim result1 As IObjectScopeQuery(Of PartnerSummary.PartnerInitiative) = From pInit In Scope.Extent(Of PartnerSummary.PartnerInitiative)() _ 
                Where pInit.PartnerSummaryID = mPartnerSummaryID _ 
                Select pInit 
     
          Dim initiatives As IObjectScopeQuery(Of PartnerSummary.Initiative) = From I In Scope.Extent(Of PartnerSummary.Initiative)() Select I 
     
          Dim tmp1 As List(Of PartnerSummary.Initiative) = initiatives.ToList() 
          Dim tmp2 As List(Of PartnerSummary.PartnerInitiative) = result1.ToList 
          'Dim tmp1 As IObjectScopeQuery(Of PartnerSummary.Initiative) = initiatives 
          ' Dim tmp2 As IObjectScopeQuery(Of PartnerSummary.PartnerInitiative) = result1 
     
          Dim result = From Inits In tmp1 _ 
                      Group Join pInit In tmp2 _ 
                      On Inits.InitiativeID Equals pInit.Id _ 
                      Into OV = Group _ 
                      From pInit2 In OV.DefaultIfEmpty(New PartnerSummary.PartnerInitiative()) _ 
         Select New PartnerSummary.PartnerInitiativeQuestions With { _ 
             .InitiativeID = Inits.InitiativeID, _ 
             .Description = Inits.Description, _ 
             .Value = If(OV Is Nothing, 0, pInit2.Value), _ 
             .Comment = If(OV Is Nothing"", pInit2.Comment), _ 
             .PartnerIniativesID = If(OV Is Nothing, 0, pInit2.PartnerIntiativesID)} 
     
     
     
          rptInitiatives.DataSource = result.ToList 


    Note: It I use the tmp1\tmp2 and the IObjectScope variable instead of converting it to Lists first it still comes back with the error : "The Last accepted query piece is not from the this query"
  3. DevCraft banner
  4. PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 08 Feb 2010 Link to this post

    Hello Matt,

    This was an old bug in our LINQ implementation. If you download the latest version of the product from our web site, the query should work normally. Please feel free to contact us if you face any further difficulties.

    Sincerely yours,
    Petar
    the Telerik team

    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Follow the status of features or bugs in PITS and vote for them to affect their priority.
  5. jon
    jon avatar
    33 posts
    Member since:
    Dec 2008

    Posted 12 Feb 2010 Link to this post

    My Projection class is working fine, but I'm still struggling with my group join.  I'm trying to display 1 record for each animal, and I have 2+ matching records in my Genotype table, but I only want to display 1 record for each animal in my result set.  But the trick is that I want to concatenate all the matching genotype values and display them in my 1 animal row in my result set.

    List<AnimalGenotypeProjection> result = (from a in scope.Extent<Animal>()

    join g in scope.Extent<Genotype>() on a.AnimalId equals g.ClientId
    select new AnimalGenotypeProjection()
    {

      IdAnimal = a.IdAnimal,

      AnimalId = a.AnimalId,

      GenotypeCode =   g.GenotypeCode
    }

    This is much harder than I imagined.  Is this possible?

  6. Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 18 Feb 2010 Link to this post

    Hi jon,

    With the query as you have written it is not really possible to obtain all genotype records matching one animal record. From the previous post, I assume than Animal and Genotype are in a 1:n relation in your model. If that is true, it is possible for you to map the Animal record so it contains a collection of Genotype records as a property. That way you will have access to all of the Genotype records that match certain animal record. Than when you make a query that returns all the animal records, you will also get the Genotype records for each animal.

    Kind regards,
    Zoran
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top
DevCraft banner