I am trying to connect my azure function to a local DB using Entity frameworkcore code 1st but I keep on getting this error when I try to add migrations,
Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider provider) at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider provider, Type instanceType, Object[] parameters) at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetServiceOrCreateInstance(IServiceProvider provider, Type type) at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.<>c__DisplayClass13_4.b__13()
but I am using the same connection string i use for all my app, just a different DB
This is my context file
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Text;
namespace FunctionApp36
{
class BookContext :DbContext
{
public BookContext(DbContextOptions<BookContext> options) : base(options)
{
}
public BookContext(DbContextOptions options) : base(options)
{
}
public BookContext() : base()
{
}
protected override void OnConfiguring(DbContextOptionsBuilder options) => options.UseSqlServer("Data Source=ABS\\SQLEXPRESS;Initial Catalog=Ba;Integrated Security=True");
}
}
and this is my startup file
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Hosting;
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Configuration;
using FunctionApp36;
[assembly: WebJobsStartup(typeof(StartUp))]
namespace FunctionApp36
{
public class StartUp : IWebJobsStartup
{
public void Configure(IWebJobsBuilder builder)
{
var config = new ConfigurationBuilder()
.AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
builder.Services.AddDbContext<BookContext>(options1 =>
{
options1.UseSqlServer(
config["ConnectionStrings:DefaultConnection"],
builder =>
{
builder.EnableRetryOnFailure(5, TimeSpan.FromSeconds(10), null);
builder.CommandTimeout(10);
}
);
});
}
}
}