This is a migrated thread and some comments may be shown as answers.

Group Join Linq problem

4 Answers 100 Views
LINQ (LINQ specific questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
MNP
Top achievements
Rank 1
MNP asked on 03 Feb 2010, 09:45 PM
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

4 Answers, 1 is accepted

Sort by
0
MNP
Top achievements
Rank 1
answered on 03 Feb 2010, 10:47 PM
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"
0
PetarP
Telerik team
answered on 08 Feb 2010, 06:44 PM
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.
0
jon
Top achievements
Rank 1
answered on 12 Feb 2010, 11:58 PM

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?

0
Zoran
Telerik team
answered on 18 Feb 2010, 09:01 AM
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.
Tags
LINQ (LINQ specific questions)
Asked by
MNP
Top achievements
Rank 1
Answers by
MNP
Top achievements
Rank 1
PetarP
Telerik team
jon
Top achievements
Rank 1
Zoran
Telerik team
Share this question
or