0

So this is the full error message i receive. (see title)

See the Postman error here

I am hosting an ASP.NET Web API on Azure, as well as an Azure SQL Database. I have connected my .edmx to the Azure Database, so it shows me the models from my hosted DB with no problems.

My huge frustration is the fact that i cannot send an API get request call whatsoever!

    [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;
    }

Here is my connection string (omitted password and username for obvious reasons with '')

 <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>

This call just gets a list of car colours. But each time I run the call on Postman, i get that frustrating 500 error. Thanks to this I could luckily find a fix to show more information. But am uncertain on what to do to fix it.

Hence my question, how do i fix the "Unintended Code First" error I am receiving?

Disclaimer: I am a university student (a.k.a very novice programmer), as such i apologize in advance if I'm using the incorrect jargon, and/or am not specific/clear enough.

Gideon Botha
  • 126
  • 10
  • Have you checked that the connection string starts with metadata? – insane_developer Aug 31 '20 at 23:02
  • If you have access, the server logs might give you an idea why you get the... – 500 - Internal Server Error Aug 31 '20 at 23:19
  • @insane_developer Added the connection string. Thanks for reminding me! It seems i do have my string starting with metadata – Gideon Botha Aug 31 '20 at 23:26
  • @GideonBotha did you try commenting out the line that throws this exception? It would be in your DbContext class. – insane_developer Aug 31 '20 at 23:39
  • @insane_developer where would i find the DbContext class exactly? (i can't seem to find it. Might be looking in the wrong place) – Gideon Botha Aug 31 '20 at 23:47
  • Search the entire solution for `UnintendedCodeFirstException`. You are looking for the code that is throwing this exception. This will probably not solve your problem, though, but it's worth a shot. I never use this GUI tools, so I don't really know what else to tell you from personal experience. – insane_developer Sep 01 '20 at 00:12
  • @500-InternalServerError I am hosting on Azure, any personal experience as to where i can find the server logs on the website? – Gideon Botha Sep 01 '20 at 08:43

1 Answers1

0

Figured out my problem

Azure did not like it that my Entity Framework models were created using the Pluralize function

After deleting the model, unticking pluralization, my Azure Web API could finally take requests and communicate with the Azure SQL Database

Gideon Botha
  • 126
  • 10