c# - DbParameterCollection不包含AddWithValue的定义

标签 c# asp.net-core entity-framework-core

在以下代码的最后一行获得上述错误。我正在使用EF Core 1.1。尝试遵循this建议。

using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient; //Visual Studio had greyed out this line suggesting this as unnecessary.

var conn = _context.Database.GetDbConnection();

var cmd = conn.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "MySproc";
cmd.Parameters.AddWithValue("@MyParameter", 42);

最佳答案

添加对System.Data.SqlClient的引用,并将DbConnection实例强制转换为SqlConnection。

关于c# - DbParameterCollection不包含AddWithValue的定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43946779/

相关文章:

entity-framework-core - EF Core 2.0 提供程序特定的模型配置

c# - 为什么 edmx 图不创建数据注释

c# - 添加对 EvalWrapper.dll 的引用时发出警告

c# - Asp.net core 为身份创建接口(interface)

asp.net-core - VS2017 中的.NET Core 1.1 : DbContextOptionsBuilder does not contain a definition for 'UseSqlServer'

sql - FromSqlRaw注入(inject)EF Core 3.0

c# - 如何使用按位&(和)来实现这个?

c# - 页面上的应用程序错误,我做错了什么?

c# - 如何仅通过 userinfo 端点而不是访问 token 获取声明

entity-framework-core - Entity Framework Core 1.0 CurrentValues.SetValues() 不存在