In Visual Studio I have an Azure Function, written in C#, which is supposed to read from an Azure SQL database using Entity Framework (EF6).
I cannot get Entity Framework to work. When I publish the Azure Function I get the error:
The context is being used in Code First mode with code that was generated from an EDMX file for either Database First or Model First development. This will not work correctly. To fix this problem do not remove the line of code that throws this exception. If you wish to use Database First or Model First, then make sure that the Entity Framework connection string is included in the app.config or web.config of the start-up project. If you are creating your own DbConnection, then make sure that it is an EntityConnection and not some other type of DbConnection, and that you pass it to one of the base DbContext constructors that take a DbConnection. To learn more about Code First, Database First, and Model First see the Entity Framework documentation here: http://go.microsoft.com/fwlink/?LinkId=394715
None of this worked.
I also tried to add a project.json file in Azure as recommended by many websites but that didn’t change anything.
Here is the C#.
public static class Function1
{
[FunctionName("Function1")]
public static void Run([TimerTrigger("*/100 * * * * *")]TimerInfo myTimer, TraceWriter log)
{
try {
using (var qc = new quotecandyEntities()) {
if (qc.Users.Any()) {
log.Info($"The last user is {qc.Users.Last().Email}.");
} else {
log.Info("No users found in database.");
}
}
} catch (Exception ex) {
log.Error($"Error: {ex.Message}");
}
}
}