Strange sql generated from EF query

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for PostgreSQL
Post Reply
TopSviluppo
Posts: 7
Joined: Fri 19 Dec 2014 07:42

Strange sql generated from EF query

Post by TopSviluppo » Fri 19 Dec 2014 07:45

We are using a registered version of DotConnect for PostgreSQL (7.3.274.6) with Entity Framework 6 and are testing some basic query using LINQ and Expression Trees.

Writing a small program like:

using (DBAuraContext context = new DBAuraContext(utente.Utente.ORMConfiguration))
{
IQueryable<Assortimenti> query = context.Assortimenti;
DateTime val = new DateTime(2010, 1, 1, 0, 0, 0);
query = query.Where(r => r.DataOraAggiornamento.Value.CompareTo(val) >= 0);
query = query.OrderBy(r => r.CodiceAssortimento);
string sql = query.ToString();
Console.WriteLine(sql);
}

we see this generated sql statement:

SELECT
Project1.IDAssortimenti,
Project1.CodiceAssortimento,
Project1.Descrizione,
Project1.Tipo,
Project1.DataOraAggiornamento,
Project1.RowVersion
FROM ( SELECT
Extent1.IDAssortimenti,
Extent1.CodiceAssortimento,
Extent1.Descrizione,
Extent1.Tipo,
Extent1.DataOraAggiornamento,
Extent1.RowVersion
FROM Assortimenti AS Extent1
WHERE Extent1.DataOraAggiornamento >= :p__linq__0
) AS Project1
ORDER BY Project1.CodiceAssortimento ASC

while we would expect something like:

SELECT
Extent1.IDAssortimenti,
Extent1.CodiceAssortimento,
Extent1.Descrizione,
Extent1.Tipo,
Extent1.DataOraAggiornamento,
Extent1.RowVersion
FROM Assortimenti AS Extent1
WHERE Extent1.DataOraAggiornamento >= :p__linq__0
ORDER BY Extent1.CodiceAssortimento ASC

Is this behaviour normal ?

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Strange sql generated from EF query

Post by Shalex » Fri 19 Dec 2014 13:32

Thank you for your report. We will investigate the issue with extra subselect when using ordering and notify you about the result.

TopSviluppo
Posts: 7
Joined: Fri 19 Dec 2014 07:42

Re: Strange sql generated from EF query

Post by TopSviluppo » Mon 19 Jan 2015 15:36

Any news about this issue ?

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Strange sql generated from EF query

Post by Shalex » Tue 20 Jan 2015 18:01

The investigation is in progress. As soon as we have any results, we will let you know.

TopSviluppo
Posts: 7
Joined: Fri 19 Dec 2014 07:42

Re: Strange sql generated from EF query

Post by TopSviluppo » Wed 21 Jan 2015 10:28

OK, Thank you

Post Reply