未部署实体框架代码优先数据库

时间:2020-03-26 17:20:51

标签: c# entity-framework iis ef-code-first webdeploy

我正在尝试使用Visual Studio 2019在迁移时首先使用Entity Framework Code部署Web API。部署工作正常,因为我的测试请求返回了我期望的结果。但是,数据库似乎没有生成,因为尝试获取所有员工时出现错误。

在我的Web.config中,我的连接字符串如下所示:

<connectionStrings>
<add name="ProjetCVC_DB" connectionString="data source=(LocalDb)\MSSQLLocalDB;initial 
     catalog=ProjetCVC_DB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework" 
     providerName="System.Data.SqlClient" />
</connectionStrings>

LocalDB已安装在服务器上

这是我的员工控制人:

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.Migrations;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Description;
using ProjetCVC_API.Models;

namespace ProjetCVC_API.Controllers
{
    [RoutePrefix("api/Employees")]
    public class EmployeesController : ApiController
    {
    private DataContext _db = new DataContext();

    // GET: api/Employees
    [HttpGet]
    [Route("")]
    public IQueryable<Employee> GetEmployees()
    {
        return _db.Employees.Include(e => e.Roles);
    }

    [HttpGet]
    [Route("Test")]
    [ResponseType(typeof(string))]
    public IHttpActionResult Test()
    {
        return Ok("Hello world!");
    }


    protected override void Dispose(bool disposing)
    {
        if (disposing)
        {
            _db.Dispose();
        }
        base.Dispose(disposing);
    }

    private bool EmployeeExists(int id)
    {
        return _db.Employees.Count(e => e.EmployeeID == id) > 0;
    }
}
}

这是我的测试请求的结果: enter image description here

这是客户端发出的我的GetEmployees请求的结果: enter image description here

来自服务器: enter image description here

这是我的Web部署发布配置文件: enter image description here enter image description here

我希望数据库生成并应用所有迁移。我尝试了很多事情,但无法正常工作。

0 个答案:

没有答案