ef4中的ExecuteStoreQuery语法错误

时间:2013-06-04 15:56:09

标签: c# entity-framework

有人知道为什么这会在@table附近给出错误的语法异常?

object[] changeQueryParams = new object[] { new SqlParameter("table", dbContext.tXSell.EntitySet.Name), new SqlParameter("fromversion", 0) };

string changeQueryString = @"SELECT * FROM CHANGETABLE(CHANGES @table, @fromversion) AS ch";

ObjectResult<object> changes = dbContext.ExecuteStoreQuery<object>(changeQueryString, changeQueryParams);

我正在使用mssql 2008 r2,ef4,c#。

1 个答案:

答案 0 :(得分:1)

您不能将表名作为参数传递给CHANGETABLE SQL函数。您可以尝试动态构建SQL。它应该是安全的sql注入,因为你只是连接EntitySet.Name属性的值。

string changeQueryString = @"SELECT * FROM CHANGETABLE(CHANGES " + dbContext.tXSell.EntitySet.Name +" , @fromversion) AS ch";