Open GoogleCodeExporter opened 9 years ago
Test case PostgreSql_test.ReadTest.C4_CountWithOrderBy() looks like it covers
this issue.
Original comment by emp....@gmail.com
on 19 Oct 2009 at 5:04
Workaround: call .ToList() before enumerating the results (and optionally
AsQueryable() if you need an IQueryable, eg.
var countriesByGroup = db.Countries.GroupBy(c =>
c.IncomeGroup).ToList().AsQueryable();
Original comment by emp....@gmail.com
on 19 Oct 2009 at 6:52
PostgreSql_test.ReadTest.C4_CountWithOrderBy() doesn't cover it.
What covers it is ReadTest_GroupBy.G02_SimpleGroup_First(), which does
effectively the same thing (but
adds a .First() call). The exception under SQL Server is the same, or close
enough:
Test_NUnit_MsSql.ReadTest_GroupBy.G02_SimpleGroup_First:
System.Data.SqlClient.SqlException : Column 'dbo.Customers.CustomerID' is
invalid in the select list
because it is not contained in either an aggregate function or the GROUP BY
clause.
What's interesting is the SQL that Linq-to-SQL produces:
SELECT TOP (1) [t1].[City] AS [Key]
FROM (
SELECT [t0].[City]
FROM [dbo].[Customers] AS [t0]
GROUP BY [t0].[City]
) AS [t1]
-- Context: SqlProvider(Sql2008) Model: AttributedMetaModel Build:
3.5.30729.4926
SELECT [t0].[CustomerID], [t0].[CompanyName], [t0].[ContactName],
[t0].[ContactTitle], [t0].[Address],
[t0].[City], [t0].[Region], [t0].[PostalCode], [t0].[Country], [t0].[Phone],
[t0].[Fax]
FROM [dbo].[Customers] AS [t0]
WHERE ((@x1 IS NULL) AND ([t0].[City] IS NULL)) OR ((@x1 IS NOT NULL) AND
([t0].[City] IS NOT NULL)
AND (@x1 = [t0].[City]))
-- @x1: Input NVarChar (Size = 6; Prec = 0; Scale = 0) [Aachen]
-- Context: SqlProvider(Sql2008) Model: AttributedMetaModel Build:
3.5.30729.4926
The 'SELECT TOP' is from the .First() call, and can be ignored; what's key is
that we have two SQL
calls generated for the .GroupBy() LINQ expression, the first SQL expression to
get the key, and the
second one to perform the query with the given key.
I don't know if DbLinq currently has support for doing interelated SQL calls in
this fashion...
Original comment by jonmpr...@gmail.com
on 21 Jan 2010 at 10:30
Please, try out the solution on the link below:
http://code.google.com/p/dblinq2007/issues/detail?id=132#c2
Original comment by tos.oliv...@gmail.com
on 1 Apr 2012 at 1:16
Original issue reported on code.google.com by
emp....@gmail.com
on 14 Oct 2009 at 6:30