小编bha*_*a.m的帖子

应用程序中断访问dbcontext,Asp .net核心web api 2.0与实体框架核心2.0数据库的第一种方法

我用EntityFrameworkCore.SqlServer 2.0开发了asp .net核心wep 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;");
        }
    }
Run Code Online (Sandbox Code Playgroud)

下面的代码块用于访问控制器中的dbcontext实体

    // GET api/values
    [HttpGet]
    public IEnumerable<string> Get()
    {
        VotingAppDBContext context = new VotingAppDBContext();
        var questions = context.Questions.ToList();
        return new string[] { "value1", "value2" };
    }
Run Code Online (Sandbox Code Playgroud)

已安装的包裹

应用程序错误

entity-framework-6 entity-framework-core asp.net-core-mvc asp.net-core asp.net-core-webapi

7
推荐指数
1
解决办法
643
查看次数