Group by problem

Posts   
 
    
Piedro
User
Posts: 24
Joined: 17-Jan-2007
# Posted on: 01-Jun-2010 11:51:52   

Hi,

I'm using LLBLGen Pro v2.6 on a SQL 2005 database, using LINQ-queries. DLL-versions: SD.LLBLGen.Pro.DQE.SqlServer.NET20.dll: 2.6.9.917 SD.LLBLGen.Pro.LinqSupportClasses.NET35.dll: 2.6.10.315

In our DB we have the addresses of the company stored in a separate table: CompanyAddress. Now I'm trying to build a LINQ-query to select per company, the first available address. (this will be a subquery of a bigger query)

I first wrote this query using LinqPad to make sure it works in LINQ.

var queryAddress = from ca in CompanyAddresses
                    group ca by ca.CompanyId into g
                    select new 
                    {
                        CompanyId = g.Key,
                        CompanyAddressId = g.First().Id
                    };

But this query gives an error when I execute it: Invalid column name 'Id'. when I check the query that gets executed on the DB, there is indeed a problem in the SQL that is being generated.

SELECT  [LPA_L1].[CompanyId]
      , (SELECT TOP 1
                [LPA_L1].[Id]
         FROM   [NewEbp].[dbo].[CompanyAddress] [LPLA_2]) AS [CompanyAddressId]
FROM    (SELECT [LPLA_1].[CompanyId]
         FROM   [NewEbp].[dbo].[CompanyAddress] [LPLA_1]
         GROUP BY [LPLA_1].[CompanyId]) [LPA_L1]

Is this a bug or am I doing something wrong? Or is there another or easier way to get this done?

Kind regards,

Peter

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 01-Jun-2010 20:21:02   

This looks like it should work... Please can you ensure that you are using the latest version of the runtime libraries from the customer area of the main website, and try it against these...

Thanks

Matt

Piedro
User
Posts: 24
Joined: 17-Jan-2007
# Posted on: 28-Jun-2010 16:31:25   

I'm using versions:

  • DQE.SqlServer: 2.6.9.917
  • ORMSupportClasses: 2.6.10.421
  • LinqSupportClasses: 2.6.10.315

I think these are the latest versions (at the moment of writing, that is).

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 29-Jun-2010 07:55:58   

But this query gives an error when I execute it: Invalid column name 'Id'. when I check the query that gets executed on the DB, there is indeed a problem in the SQL that is being generated.

Please post the exact exception text and stack trace.