有人知道为什么这会在@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#。
答案 0 :(得分:1)
您不能将表名作为参数传递给CHANGETABLE SQL函数。您可以尝试动态构建SQL。它应该是安全的sql注入,因为你只是连接EntitySet.Name
属性的值。
string changeQueryString = @"SELECT * FROM CHANGETABLE(CHANGES " + dbContext.tXSell.EntitySet.Name +" , @fromversion) AS ch";