This question is locked. New answers and comments are not allowed.
I have the following LINQ query:
When I execute it, I get an InvalidOperationException with the message:
An exception occured during the execution of '
Extent<Il.Data.Agent>.Where(a => value(AgentMigrationApp.IlFeatureDefinitions+<>c__DisplayClass64).dc.AgentLeads.Any(al => (Convert(a.Id) = al.Agentid)))'. See InnerException for more details.
...which has a Telerik.OpenAccess.Exceptions.DataStoreException inner exception with the following message:
{"Count(*) query failed: Telerik.OpenAccess.RT.sql.SQLException: Incorrect syntax near '='.\r\n at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.executeQuery()\r\n at OpenAccessRuntime.Relational.conn.PooledPreparedStatement.executeQuery()\r\n at OpenAccessRuntime.Relational.RelationalStorageManager.executeCount(RelationalCompiledQuery cq, QueryParameters parameters)\nSELECT COUNT(1) FROM ( SELECT (CASE WHEN COUNT(1) > 0 THEN 1 ELSE 0 END) AS EXPR1 FROM [agent] a WHERE (SELECT (CASE WHEN COUNT(1) > 0 THEN 1 ELSE 0 END) FROM [agent_leads] b WHERE b.[id] = a.[id] = b.[agentid]) ) AS TMP_COUNT\n(set event logging to all to see parameter values) Telerik.OpenAccess.RT.sql.SQLException: Incorrect syntax near '='.\r\n at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.executeQuery()\r\n at OpenAccessRuntime.Relational.conn.PooledPreparedStatement.executeQuery()\r\n at OpenAccessRuntime.Relational.RelationalStorageManager.executeCount(RelationalCompiledQuery cq, QueryParameters parameters)"}
Here's a formatted version of the generated SQL above (for readability):
Note that the innermost WHERE clause is incorrect. I have absolutely no idea where the "b.[id] = " is coming from; there is nothing like that in my original LINQ query. What's going on here?
// Given: IQueryable<Agent> Agents
// Given: IQueryable<AgentLead> AgentLeads
var agentsQuery = Agents.Where(a => AgentLeads.Any(al => al.Agentid == a.Id
));
var count = agentsQuery.Count();
When I execute it, I get an InvalidOperationException with the message:
An exception occured during the execution of '
Extent<Il.Data.Agent>.Where(a => value(AgentMigrationApp.IlFeatureDefinitions+<>c__DisplayClass64).dc.AgentLeads.Any(al => (Convert(a.Id) = al.Agentid)))'. See InnerException for more details.
{"Count(*) query failed: Telerik.OpenAccess.RT.sql.SQLException: Incorrect syntax near '='.\r\n at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.executeQuery()\r\n at OpenAccessRuntime.Relational.conn.PooledPreparedStatement.executeQuery()\r\n at OpenAccessRuntime.Relational.RelationalStorageManager.executeCount(RelationalCompiledQuery cq, QueryParameters parameters)\nSELECT COUNT(1) FROM ( SELECT (CASE WHEN COUNT(1) > 0 THEN 1 ELSE 0 END) AS EXPR1 FROM [agent] a WHERE (SELECT (CASE WHEN COUNT(1) > 0 THEN 1 ELSE 0 END) FROM [agent_leads] b WHERE b.[id] = a.[id] = b.[agentid]) ) AS TMP_COUNT\n(set event logging to all to see parameter values) Telerik.OpenAccess.RT.sql.SQLException: Incorrect syntax near '='.\r\n at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.executeQuery()\r\n at OpenAccessRuntime.Relational.conn.PooledPreparedStatement.executeQuery()\r\n at OpenAccessRuntime.Relational.RelationalStorageManager.executeCount(RelationalCompiledQuery cq, QueryParameters parameters)"}
Here's a formatted version of the generated SQL above (for readability):
SELECT
COUNT
(1)
FROM
(
SELECT
(
CASE
WHEN
COUNT
(1) > 0
THEN
1
ELSE
0
END
)
AS
EXPR1
FROM
[agent] a
WHERE
(
SELECT
(
CASE
WHEN
COUNT
(1) > 0
THEN
1
ELSE
0
END
)
FROM
[agent_leads] b
WHERE
b.[id] = a.[id] = b.[agentid]
)
)
AS
TMP_COUNT
Note that the innermost WHERE clause is incorrect. I have absolutely no idea where the "b.[id] = " is coming from; there is nothing like that in my original LINQ query. What's going on here?