oData creates incompatible SQL

Topics: ASP.NET Web API
Apr 9, 2014 at 1:42 PM
Edited Apr 9, 2014 at 1:42 PM
I've found a case where oData is generating expression trees differently to it's counter part straight to dbcontext.

This isn't a bad thing normally, but it is generating SQL incompatible with SQL Server in compatibility mode 80. I realise a SQL server upgrade would sort this, but seeing as hitting the dbcontext directly works fine, it makes me think that somewhere in oData it's going astray.

I've posted a lengthy investigation on stackoverflow http://stackoverflow.com/questions/22942935/odatawebapi-parameters-as-arguments-to-a-top-are-not-supported-in-version
Apr 9, 2014 at 2:34 PM
After lots of digging I've uncovered the cause and the (nicely simple) fix. It would be really cool that if compatibility mode 80 was detected that it would set EnableConstantParameterization to false. But I understand this would mean being quite chatty with Entity Framework.

Perhaps just a note for the edge case gotchas.

The solution: http://stackoverflow.com/a/22965771/141022
Marked as answer by alexkey on 4/9/2014 at 7:34 AM