我开发了一个使用EntityFrameworkCore.SqlServer 2.0的asp .net core web api 2.0应用程序,采用数据库优先方法进行开发。当尝试使用dbcontext访问实体时,应用程序会进入中断模式。我找不到应用程序状态进入中断状态的原因。请帮助解决这个问题。
以下是DBContext类中的OnConfiguring方法:
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseSqlServer(@"Server=(local);Database=VotingAppDB;User ID=sa;Password=123;");
}
}
以下代码块用于在控制器中访问 dbcontext 实体。
// GET api/values
[HttpGet]
public IEnumerable<string> Get()
{
VotingAppDBContext context = new VotingAppDBContext();
var questions = context.Questions.ToList();
return new string[] { "value1", "value2" };
}