LINQ statement with multi-field group by, aggregate and joins

Posts   
 
    
Posts: 116
Joined: 18-Feb-2006
# Posted on: 25-Feb-2010 07:46:03   

Long story short, I've been trying to write a LINQ query for the following statement:

DECLARE @id int

SET @id = 3

SELECT slp.LearningProgressID, a.LastUpdatedUTC AS PendingTestDate, a.TimeZoneLookupID 
FROM
     (
     SELECT userid, learningmoduleid, MAX(instancenumber) AS MaxInstance 
     FROM studentlearningprogress
     WHERE learningmoduleid = @id
     GROUP BY userid, learningmoduleid
     ) AS LatestProgress 
 INNER JOIN studentlearningprogress slp 
    ON slp.userid = latestprogress.userid 
    AND slp.learningmoduleid = latestprogress.learningmoduleid 
    AND slp.instancenumber = latestprogress.MaxInstance 
 INNER JOIN studentlearningprogressactivity a
    ON a.studentlearningprogressid = slp.learningprogressid
 WHERE slp.studentlearningprogressstatusid = 4  
 AND a.newstudentlearningprogressstatusid = 4

I've been unsuccessful getting even the subquery of LatestProgress to return anything. I am getting a Security Exception (which is odd). Is this even possible in LINQ or do I have to use a derived table with dynamic relations to get the result set I'm looking for?

Self-Servicing, 2.6, VB.NET

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 25-Feb-2010 08:54:28   

Please post the linq query, the exception text, the stack trace and the LLBLGen runtime library version.

Thanks.

Posts: 116
Joined: 18-Feb-2006
# Posted on: 25-Feb-2010 16:49:37   

ORMSupportClasses runtime version 2.6.09.0903

The security exception was something to do with the database being remote, I bypassed it and I'm getting the "Grouping on a field in a related entity isn't supported in VB.NET" error.

I was attemping to just get the derived table correct before moving onto the next part:

Public Function TestingOutThisThing(learningModuleId as Long) as IEnumerable(of StudentLearningProgressEntity)
    Dim slp = From s In (New LinqMetaData).StudentLearningProgress _
        Where s.LearningModuleID  = learningModuleId _
        Group s By Key = New With {s.UserID, s.LearningModuleID} Into g = Group _
        Select New With {g, g.Max(Function(i) i.InstanceID)} 
    Return Ctype(slp, ILLBLGenProQuery).Execute(of StudentLearningProgressEntity)
End Function

I don't know if I'll be able to get this correctly if VB.NET group by doesn't work correctly. Maybe the DerivedTable would be better in this case?

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 25-Feb-2010 21:29:20   

Could you perhaps try it in c# to see if that works ?

Also try upgrading the latest version of 2.6 as your is rather old, and there have been a LOT of fixes to the LINQ section over the last year

Matt

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39866
Joined: 17-Aug-2003
# Posted on: 27-Feb-2010 15:39:01   

Could you please post the exact exception and stacktrace (and please try the latest runtime build first as well).

Frans Bouma | Lead developer LLBLGen Pro
Posts: 116
Joined: 18-Feb-2006
# Posted on: 04-Mar-2010 19:50:29   

I ended up just creating a view for now until I can spend more time on this issue