我正在尝试使用 Entity frameworkcore 代码 1st 将我的 azure 函数连接到本地数据库,但是当我尝试添加迁移时,我不断收到此错误,
无法解析 Microsoft.Extensions.DependencyInjection.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider 提供程序)在 Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider 提供程序,类型 instanceType,Object[] 参数)类型的服务。在 Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.<>c__DisplayClass13_4.b__13()
但我使用与我所有应用程序相同的连接字符串,只是一个不同的数据库
这是我的上下文文件
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");
}
}
这是我的启动文件
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);
}
);
});
}
}
}