엔터티 프레임 워크를 통해 MVC 프로젝트에 성공적으로 연결된 브라우저에서 데이터베이스를 보려고합니다.데이터베이스에 연결을 시도하고 Entity Framework로 현재보기를 시도합니다. 컨트롤러의 dbContext 오류 발생
그러나 일부 실행을 실행하려고 할 때 내 컨트롤러에서 dbContext
에 적용되는 문을 사용하여 오류가 계속 발생합니다.
처음에 데이터베이스에 연결했을 때 모델 생성 당시 만들어진이 db.context가 생성 된 것으로 가정합니다. 다른 곳에서 온 코드의 주석에도 불구하고 MyDatabaseEntities
은 dbContext
으로 모델 생성시 생성됩니다. 어떤 이유로 나는 지루하게 Model1
라고 불리는 컨텍스트를 사용하려고 시도했지만 그것을 인식하지 못합니다.
이유가 누구인지 아시겠습니까? 누구든지이 문제를 바로 잡도록 도와 주실 수 있습니까? Model1
는 구불 구불 한 빨간색이있는 경우 그 중 하나가 어떤 프로젝트 참조에 존재하지 않는 및/또는 네임 스페이스가 현재 파일에 포함되지 않았기 때문에
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace WebApplication6.Controllers
{
public class UserController : Controller
{
//
// GET: /User/
public ActionResult Index()
{
return View();
}
public ActionResult GetUser()
{
return View();
}
public JsonResult GetAllUser()
{
List<Location> allUser = new List<Location>();
// Here "MyDatabaseEntities " is dbContext, which is created at time of model creation.
using (Model1 dc = new Model1())
{
allUser = dc.UserMasters.ToList();
}
return new JsonResult { Data=allUser, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
}
public JsonResult GetUserWithParameter(string prefix)
{
List<Location> allUser = new List<Location>();
// Here "MyDatabaseEntities " is dbContext, which is created at time of model creation.
using (Model1 dc = new Model1())
{
allUser = dc.UserMasters.Where(a => a.Username.Contains(prefix)).ToList();
}
return new JsonResult { Data = allUser, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
}
}
}
무엇이 오류입니까? 빨간 물결 모양을 가리 키거나 오류 목록 창을 봅니다. 대부분 네임 스페이스에'using' 문만 있으면됩니다. – Crowcoder
Model1() 코드를 표시하십시오. –