The examples for System.Data.Entity.Database.SqlQuery method I’ve found appear to work well with SQL 2008 R2 but do not appear to work with SQL 2005.
This call will work with SQL 2008 R2:
var myEntities = dbContext.Database.SqlQuery<MyEntity>("GetDataFromMySp @EntityId = {0}", entityId);
However, in SQL 2005 this statement will throw a SqlException with an error message of “Incorrect syntax near ‘GetDataFromMySp'”.
Solution found by @Dan himself (couldn’t post due to rep)
The solution I found to this issue was simply to add the keyword “EXEC” to the query:
This solution fixed the issue with SQL Server 2005 and still worked with SQL Server 2008 R2.