【发布时间】:2020-12-16 06:15:07
【问题描述】:
我正在学习 DotNet Core。 这是我的控制器
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Practinig_Student.Models;
using Microsoft.EntityFrameworkCore;
using System.Data.Entity;
namespace Practinig_Student.Controllers
{
public class EmployeeController : Controller
{
private readonly EmployeeContext _dbcontext;
public EmployeeController(EmployeeContext dbContext)
{
_dbcontext = dbContext;
}
public IActionResult Employee_Details(int id)
{
// EmployeeContext employeeContext = new EmployeeContext();
//Employee employee = dbContext.Employees.Single(emp => emp.Id == id);
var emplst = dbContext.Employees.Single(emp => emp.Id == id);
return View(emplst);
}
}
}
我遇到了一个错误
var emplst = dbContext.Employees.Single(emp => emp.Id == id);
我无法访问dbContext
我得到的错误是 名称 dbContext 在当前上下文中不存在
我尝试了很多解决方案,但没有出现错误。我也不明白为什么会出现错误。帮帮我。
【问题讨论】:
标签: c# entity-framework model-view-controller .net-core