500 Internal Server Error: Unintentional Code First Exception

500 Internal Server Error: Unintentional Code First Exception

所以这是我收到的完整错误消息。 (见标题)

See the Postman error here

我在 Azure 上托管了一个 ASP.NET Web API,以及一个 Azure SQL 数据库。 我已将我的 .edmx 连接到 Azure 数据库,因此它可以毫无问题地向我显示托管数据库中的模型。

我最大的挫败感是我无法发送 API get 请求调用!

    [EnableCors(origins: "*", headers: "*", methods: "*")]
    [System.Web.Http.Route("~/api/Admin/getTest")]
   
    [System.Web.Http.HttpGet]
    public List<CARCOLOUR> getTest()
    {
        INF370KODEITEntities db = new INF370KODEITEntities();
        db.Configuration.ProxyCreationEnabled = false;

        List<CARCOLOUR> testData = db.CARCOLOURs.ToList();

        return testData;
    }

这是我的连接字符串(出于明显原因省略了密码和用户名,带有'')

 <connectionStrings>

    <add name="INF370KODEITEntities" connectionString="metadata=res://*/Models.CarwashModel.csdl|res://*/Models.CarwashModel.ssdl|res://*/Models.CarwashModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=kodeit-apidbserver-database.database.windows.net;initial catalog=KODEIT_API_db;persist security info=True;user id='';password='';MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>

此调用仅获取汽车颜色列表。但是每次我 运行 调用 Postman 时,我都会收到令人沮丧的 500 错误。感谢 this 幸运的是,我可以找到一个修复程序来显示更多信息。但不确定如何修复它。

因此我的问题是,如何解决我收到的“意外代码优先”错误?

免责声明:我是一名大学生(a.k.a 非常新手程序员),因此如果我使用了不正确的行话,我提前道歉,and/or 不是 specific/clear够了。

解决了我的问题

Azure 不喜欢我的 Entity Framework 模型是使用 Pluralize 函数创建的

  • 我在创建数据模型时选择了这个选项:数据库优先 方法
  • 取消勾选“复数化或单数化生成的对象名称” Click for image

删除模型后,取消多元化,我的 Azure Web API 终于可以接受请求并与 Azure SQL 数据库

通信