【发布时间】:2018-06-03 19:08:15
【问题描述】:
我正在使用实体框架核心的ExecuteSqlCommand 删除表的所有行。
但是,我收到一个错误System.Data.SqlClient.SqlException: 'Must declare the table variable "@p0".'
这是我的代码:
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" />
【问题讨论】:
标签: asp.net-core-2.0 entity-framework-core-2.1