Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net core 2.0 必须声明表变量“@p0”_Asp.net Core 2.0_Entity Framework Core 2.1 - Fatal编程技术网

Asp.net core 2.0 必须声明表变量“@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(

我正在使用entity framework core的ExecuteSqlCommand删除表中的所有行。 但是,我得到一个错误System.Data.SqlClient.SqlException:“必须声明表变量@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" />

看起来,即使我的查询没有使用任何参数,也必须至少向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中报告了一个类似的问题,目前正在考虑: