Asp.net core 2.0 必须声明表变量“@p0”
我正在使用entity framework core的ExecuteSqlCommand删除表中的所有行。 但是,我得到一个错误System.Data.SqlClient.SqlException:“必须声明表变量@p0。” 这是我的密码:Asp.net core 2.0 必须声明表变量“@p0”,asp.net-core-2.0,entity-framework-core-2.1,Asp.net Core 2.0,Entity Framework Core 2.1,我正在使用entity framework core的ExecuteSqlCommand删除表中的所有行。 但是,我得到一个错误System.Data.SqlClient.SqlException:“必须声明表变量@p0。” 这是我的密码: public static void ExecuteDeleteSQL(ShoppingCartDbContext context, string tableName) { context.Database.ExecuteSqlCommand(
public static void ExecuteDeleteSQL(ShoppingCartDbContext context, string tableName)
{
context.Database.ExecuteSqlCommand($"Delete from {tableName}"); //This line throws the error
}
这里称之为:
ExecuteDeleteSQL(context, "[dbo].[ShoppingCartItems]");
我正在将.NET Core 2与EntityFrameworkCore一起使用
我已安装以下nuget软件包:
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="2.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.0" />
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" />
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
看起来,即使我的查询没有使用任何参数,也必须至少向ExecuteSqlCommand传递一个参数。 令人恼火的是,它在编译时不会抱怨
//passing at least one parameter
context.Database.ExecuteSqlCommand($"Delete from {tableName}",tableName);
编辑:
GitHub中报告了一个类似的问题,目前正在考虑:
看起来,即使我的查询没有使用任何参数,您也必须至少向ExecuteSqlCommand传递一个参数。 令人恼火的是,它在编译时不会抱怨
//passing at least one parameter
context.Database.ExecuteSqlCommand($"Delete from {tableName}",tableName);
编辑:
GitHub中报告了一个类似的问题,目前正在考虑: