Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated statement contains SQL parameter as constant in column selection (causes "Data type unknown" error) [DNET345] #352

Closed
firebird-automations opened this issue Aug 18, 2010 · 3 comments

Comments

@firebird-automations
Copy link

Submitted by: Daniel Richter (danielrichter)

Some queries result in generated SQL containing projections with an SQL parameter as constant in column selection. E.g.
SELECT @p__linq__2 AS "p__linq__2" FROM Table1
which results in a "Data type unknown" error.

Containing an explicit cast. the statement is executable:
SELECT CAST(@p__linq__2 AS TIMESTAMP) AS "p__linq__2" FROM Table1

I can reproduce it by using a filter with a captured parameter and a grouping followed by a projection selecting both a group aggregate and the group itself:

DateTime dateTime = DateTime.Now;
var query = this.objectContext.TABLE1
.Select(entity => new { entity.SomeDateTime, entity.SomeValue1, entity.SomeValue2 })
.Where(entity => entity.SomeDateTime>dateTime)
.GroupBy(entity => entity.SomeValue1)
.Select(group => new
{
Sum = group.Sum(entity => entity.SomeValue2),
Values = group
})
.ToList();

@firebird-automations
Copy link
Author

Commented by: @cincuranet

Your query results into:
SELECT
"Project2"."C2" AS "C1",
"Project2"."C1" AS "C2",
"Project2"."SOMEVALUE1" AS "SOMEVALUE1",
"Project2"."C3" AS "C3",
"Project2"."SOMEDATETIME" AS "SOMEDATETIME",
"Project2"."SOMEVALUE11" AS "SOMEVALUE11",
"Project2"."SOMEVALUE2" AS "SOMEVALUE2"
FROM ( SELECT
"GroupBy1"."A1" AS "C1",
"GroupBy1"."K1" AS "SOMEVALUE1",
1 AS "C2",
"Project1"."SOMEDATETIME" AS "SOMEDATETIME",
"Project1"."SOMEVALUE1" AS "SOMEVALUE11",
"Project1"."SOMEVALUE2" AS "SOMEVALUE2",
"Project1"."C1" AS "C3"
FROM (SELECT
"Extent1"."SOMEVALUE1" AS "K1",
SUM("Extent1"."SOMEVALUE2") AS "A1"
FROM "TABLE1" AS "Extent1"
WHERE "Extent1"."SOMEDATETIME" > @p__linq__0
GROUP BY "Extent1"."SOMEVALUE1" ) AS "GroupBy1"
LEFT OUTER JOIN (SELECT
"Extent2"."SOMEDATETIME" AS "SOMEDATETIME",
"Extent2"."SOMEVALUE1" AS "SOMEVALUE1",
"Extent2"."SOMEVALUE2" AS "SOMEVALUE2",
1 AS "C1"
FROM "TABLE1" AS "Extent2" ) AS "Project1" ON ("Project1"."SOMEDATETIME" > @p__linq__0) AND (("GroupBy1"."K1" = "Project1"."SOMEVALUE1") OR (("GroupBy1"."K1" IS NULL) AND ("Project1"."SOMEVALUE1" IS NULL)))
) AS "Project2"
ORDER BY "Project2"."SOMEVALUE1" ASC, "Project2"."C3" ASC

and there's no direct selection of param. Probably your model is specific hence provide script to create the table (and updated query, if required).

@firebird-automations
Copy link
Author

Modified by: @cincuranet

status: Open [ 1 ] => In Progress [ 3 ]

@firebird-automations
Copy link
Author

Modified by: @cincuranet

status: In Progress [ 3 ] => Resolved [ 5 ]

resolution: Fixed [ 1 ]

Fix Version: 2.6.1 [ 10400 ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants