I just tried a quick sample.
Can you try the following and let me know how it goes please.
public override void Configure(IFunctionsHostBuilder builder)
{
builder.Services.AddDbContext<MyDbContext>(options =>
options
.UseSqlServer("<ConnectionString>"));
}
In your DbContext,
public class MyDbContext : DbContext
{
private readonly ILogger<MyDbContext> _logger;
public MyDbContext(DbContextOptions options, ILogger<MyDbContext> logger) : base(options)
{
_logger = logger;
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder
.LogTo(action =>
{
_logger.LogInformation(action);
// TODO: Use your implementation
});
}
}
And tried with a simple function.
public class Function1
{
private readonly MyDbContext _myDbContext;
public Function1(MyDbContext myDbContext)
{
_myDbContext = myDbContext;
}
[FunctionName("Function1")]
public async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
_myDbContext.Database.EnsureCreated();
await _myDbContext.Employees.AddAsync(new Employee() { Name = "John Doe" });
await _myDbContext.SaveChangesAsync();
return new OkResult();
}
}