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