简体   繁体   English

EntityFramework Core 的问题 - 尝试为身份表添加迁移 - SQLite

[英]Issue with EntityFramework Core - trying to add migration for Identity Tables - SQLite

I have created a Razor Pages web application which has its own context class, and works fine with EF Core.Sqlite我创建了一个 Razor Pages web 应用程序,它有自己的上下文 class,并且可以与 EF Core.Z283F04AC146A4012BFABB66 一起正常工作

I decided to add Identity to my application, and currently running into issues when trying to add a migration.我决定将 Identity 添加到我的应用程序中,但目前在尝试添加迁移时遇到了问题。 I've googled the error but no joy.我用谷歌搜索了错误,但并不高兴。

PM> Add-Migration BakeryIdentity -Context BakeryAppUsersContext
Build started...
Build succeeded.
An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing without the application service provider. Error: Method 'Create' in type 'Microsoft.EntityFrameworkCore.Sqlite.Query.Internal.SqliteQueryableMethodTranslatingExpressionVisitorFactory' from assembly 'Microsoft.EntityFrameworkCore.Sqlite, Version=3.1.5.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' does not have an implementation.
Unable to create an object of type 'BakeryAppUsersContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728

BakerAppUsersContext is the Context class created by Identity. BakerAppUsersContext是 Identity 创建的 Context class。 I have registered this Context class within my Startup.cs :我已经在我的Startup.cs中注册了这个上下文 class :

public void ConfigureServices(IServiceCollection services)
{
    services.AddRazorPages();
    services.AddDbContext<BakeryContext>();
    services.AddEntityFrameworkSqlite().AddDbContext<BakeryAppUsersContext>();
}

Below is the Context class added by Identity:下面是 Identity 添加的 Context class:

using BakeryApp.Areas.Identity.Data;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;

namespace BakeryApp.Data
{
    public class BakeryAppUsersContext : IdentityDbContext<BakeryAppAdmin>
    {
        public BakeryAppUsersContext(DbContextOptions<BakeryAppUsersContext> options)
            : base(options)
        {
        }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseSqlite(@"Data source=Bakery.db");
        }

        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);
            // Customize the ASP.NET Identity model and override the defaults if needed.
            // For example, you can rename the ASP.NET Identity table names and more.
            // Add your customizations after calling base.OnModelCreating(builder);
        }
    }
}

Finally, below is the code from IdentityHostingStartup.cs which was created by the scaffolded code.最后,下面是由脚手架代码创建的IdentityHostingStartup.cs中的代码。

using BakeryApp.Areas.Identity.Data;
using BakeryApp.Data;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

[assembly: HostingStartup(typeof(BakeryApp.Areas.Identity.IdentityHostingStartup))]
namespace BakeryApp.Areas.Identity
{
    public class IdentityHostingStartup : IHostingStartup
    {
        public void Configure(IWebHostBuilder builder)
        {
            builder.ConfigureServices((context, services) => {
                services.AddDbContext<BakeryAppUsersContext>(options =>
                    options.UseSqlite(
                        context.Configuration.GetConnectionString("BakeryAppUsersContextConnection")));

                services.AddDefaultIdentity<BakeryAppAdmin>(options => options.SignIn.RequireConfirmedAccount = true)
                    .AddEntityFrameworkStores<BakeryAppUsersContext>();
            });
        }
    }
}

Any ideas or pointers will be appreciated.任何想法或指针将不胜感激。

You need to install the SQLLite version that matches the EntityFrameworkCore version you are using;您需要安装与您正在使用的 EntityFrameworkCore 版本相匹配的 SQLLite 版本; ie. IE。 if 5.0 preview for both.如果两者都是 5.0 预览版。

I just met the same Exception.我刚刚遇到了同样的异常。

Check the nuget Microsoft.EntityFrameworkCore.Tools version.检查 nuget Microsoft.EntityFrameworkCore.Tools 版本。 It istalled previews version -5.0 by mistake.它错误地安装了预览版-5.0。

reinstall 3.1.5 version.重新安装 3.1.5 版本。 now it's solved现在解决了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 进行添加迁移时,EntityFramework核心模型关系问题 - EntityFramework core model relationship issue while doing Add-Migration .net核心EntityFramework“添加迁移”无效 - .net core EntityFramework “Add-Migration” not working EntityFramework Core 2.0 - 添加迁移错误“未安装 EntityFramework 包” - EntityFramework Core 2.0 - Add Migration error "The EntityFramework package is not installed" 创建初始迁移 .NET Core &amp; EntityFramework &amp; PostgreSQL 的问题 - Issue creating initial migration .NET Core & EntityFramework & PostgreSQL 如何在 asp.net 核心标识中添加表 - How to add tables in asp.net core Identity EntityFramework 核心 SQLite 与列表<t>覆盖当前 ID 值而不是添加下一个 ID</t> - EntityFramework Core SQLite with List<T> overriding current ID value instead of add next ID SQLite 数据库中的 EntityFramework 核心格式 DateTime - EntityFramework Core format DateTime in sqlite database 实体框架尝试添加数据库中已有表的迁移 - Entity Framework trying to add migration of tables that are already in database Identity Core 2注册问题 - Identity Core 2 issue with registration 实体框架迁移 - 尝试添加种子数据时出现问题 - Entity Framework migration - issue when trying to add seed data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM