Can the same linq expression be translated to different SQL statement depending on the DB?

135 Views Asked by At

I have been working on a ASP.NET MVC project where we use Informix DB and Entity Framework for our queries. The thing is that depending on which DB the application is connected to, some LINQ queries are translated to different SQL queries.

That is I connect to DB 1 and the query is working and is translated more or less like this:

Opened connection asynchronously at 26/9/2019 12:48:27 +03:00
SELECT SKIP 0 FIRST 25 
...
FROM ( SELECT ...
    FROM ( SELECT 
        ...
        FROM   LATERAL (SELECT 
            ... ) AS Project1
        LEFT OUTER JOIN  LATERAL (SELECT  FIRST 1 Project2.C1 AS C1
            FROM  LATERAL ( SELECT 
                ...
            )  AS Project2
            ORDER BY ... ASC ) AS Limit1 ON 1 = 1 
    )  AS Project3
)  AS Project3
ORDER BY ...
-- p__linq__0: 'M' (Type = String, Size = 1)
-- p__linq__1: '1/1/2018 00:00:00' (Type = DateTime, Size = 16)
-- p__linq__2: '1/1/2019 00:00:00' (Type = DateTime, Size = 16)
-- Executing asynchronously at 26/9/2019 12:48:27 +03:00

using the same exact code I restart the application and connect to DB 2 and the same LINQ expression is translated to the following SQL query that fails:

Opened connection asynchronously at 26/9/2019 12:41:00 +03:00
SELECT SKIP 0 FIRST 25 
...
FROM ( SELECT ...
    FROM ( SELECT 
        ...
        FROM   (SELECT 
            ... ) AS Project1
        LEFT OUTER JOIN  (SELECT  FIRST 1 Project2.C1 AS C1
            FROM ( SELECT 
                ...
            )  AS Project2
            ORDER BY ... ASC ) AS Limit1 ON 1 = 1 
    )  AS Project3
)  AS Project3
ORDER BY ...
-- p__linq__0: 'M' (Type = String, Size = 1)
-- p__linq__1: '1/1/2018 00:00:00' (Type = DateTime, Size = 16)
-- p__linq__2: '1/1/2019 00:00:00' (Type = DateTime, Size = 16)
-- Executing asynchronously at 26/9/2019 12:41:00 +03:00
-- Failed in 403 ms with error: ERROR [IX000] [IBM][IDS/UNIX64] Column (...) not found in any table in the query (or SLV is undefined). 

You can notice that the second query is missing the LATERAL keyword. Is it possible that just the DB connected, affects the LINQ translation to SQL?

edit to answer questions: @Fildor the DBs are not the exact same version:

- DB1 is IBM Informix Dynamic Server Version 12.10.FC6WE
- DB2 is IBM Informix Dynamic Server Version 12.10.FC10

@Corak as far as I know the DB schema regarding the missing column is the same in both DBs. Since I cannot be 100% sure though, could that be the case? All columns are there though, if there is any difference it will be in foreign keys i.e. The thing is that the two queries are exactly the same with the only difference being the LATERAL keyword. This is the documentation of IBM regarding LATERAL keyword. It makes sense to me that without it the "missing" column cannot be found in the subquery.

0

There are 0 best solutions below