Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# .net核心表不';不存在_C#_.net Core_Entity Framework Core - Fatal编程技术网

C# .net核心表不';不存在

C# .net核心表不';不存在,c#,.net-core,entity-framework-core,C#,.net Core,Entity Framework Core,我的问题是:我有授权和认证的项目。我已经为这些添加了一些模型(文章、类别)、回购和IREPO。数据库仅显示由identity framework创建的表。没有我自己的!我已经完成了迁移并更新了数据库。下面是SQLSOE的屏幕 启动: public void ConfigureServices(IServiceCollection services) { services.AddDbContext<ApplicationDbContext>(options =

我的问题是:我有授权和认证的项目。我已经为这些添加了一些模型(文章、类别)、回购和IREPO。数据库仅显示由identity framework创建的表。没有我自己的!我已经完成了迁移并更新了数据库。下面是SQLSOE的屏幕

启动:

public void ConfigureServices(IServiceCollection services)
    {
        services.AddDbContext<ApplicationDbContext>(options =>
            options.UseSqlServer(
                Configuration.GetConnectionString("DefaultConnection")));
        services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
            .AddEntityFrameworkStores<ApplicationDbContext>();
        services.AddControllersWithViews();
        services.AddRazorPages();
        services.AddTransient<IArticleRepository, ArticleRepository>();
        services.AddTransient<ICategoryRepository, CategoryRepository>();
    }
public void配置服务(IServiceCollection服务)
{
services.AddDbContext(选项=>
options.UseSqlServer(
GetConnectionString(“DefaultConnection”);
services.AddDefaultIdentity(options=>options.SignIn.RequireConfirmedAccount=true)
.AddEntityFrameworkStores();
services.AddControllersWithViews();
services.AddRazorPages();
services.AddTransient();
services.AddTransient();
}
DBcontext:

using System;
using System.Collections.Generic;
using System.Text;
using Blog.Models;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;

namespace Blog.Data
{
public class ApplicationDbContext : IdentityDbContext
{
    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
        : base(options)
    {
    }

    public DbSet<Article> Articles;
    public DbSet<Category> Categories;
    public DbSet<IdentityUser> Users;

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Article>().HasData(new Article { Id=1, CategoryId=1, Content="cont", Title="title" });
    }
}
使用系统;
使用System.Collections.Generic;
使用系统文本;
使用Blog.Models;
使用Microsoft.AspNetCore.Identity;
使用Microsoft.AspNetCore.Identity.EntityFrameworkCore;
使用Microsoft.EntityFrameworkCore;
命名空间Blog.Data
{
公共类ApplicationDbContext:IdentityDbContext
{
公共应用程序DBContext(DbContextOptions选项)
:基本(选项)
{
}
公共DbSet文章;
公共数据库集类别;
公共数据库集用户;
模型创建时受保护的覆盖无效(ModelBuilder ModelBuilder)
{
modelBuilder.Entity().HasData(新文章{Id=1,CategoryId=1,Content=“cont”,Title=“Title”});
}
}

}我删除了数据库和所有迁移。增加

 protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
    }

迁移和更新后-正常工作。

这通常是因为数据库不在您希望看到的位置。如果您已经运行了迁移,它们应该在迁移表中吗?您能否显示有关您希望数据库位于何处(来自EF设置)的信息,以及您在“SQL SOE”中看到的内容(不管是什么!)@stuartd Yeah-BlogDb(如屏幕上所示)是我的数据库。我的表(类别、文章)应该与用户标识“一行”。SQL SOE-SQL Server对象资源管理器。@stuartd BTW:如何检查EF设置?