What causes “Incorrect syntax near ” in EF Code First and SQL 2005?

后端 未结 2 511
醉梦人生
醉梦人生 2021-02-15 10:24

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 wor

2条回答
  •  日久生厌
    2021-02-15 11:11

    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:

    var myEntities = dbContext.Database.SqlQuery("EXEC GetDataFromMySp @EntityId = {0}", entityId);
    

    This solution fixed the issue with SQL Server 2005 and still worked with SQL Server 2008 R2.

提交回复
热议问题