0

私は、EFコアを使用して新しいASP.NetコアWebサイトを構築し始めました。 Visual StudioでUser Authenticaionを使用して通常のテンプレートを使用してテンプレートを作成しました。非常に基本的。 ApplicationDbContextと移行が含まれており、IDテーブルでデータベースを正常に更新しました。 それから、私自身のクラスを追加し、それらをDbSetとしてApplicationDbContextに追加します。 Add-Migrationを試してみましたが、UpメソッドとDownメソッドは空です。私は別のソリューションを試しましたが、dbsetをdbコンテキストクラスに追加することをお勧めします。 私はここで何が見えないのですか?EFコアの移行は、ASP.NETコアWebプロジェクトでは機能しません。空の上/下

ApplicationDbContext

public class ApplicationDbContext : IdentityDbContext<ApplicationUser> 
{ 
    public DbSet<Customer> Customers { get; set; } 
    public DbSet<UserManual> UserManuals { get; set; } 

    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) 
     : base(options) 
    { 
    } 

    protected override void OnModelCreating(ModelBuilder builder) 
    { 
     builder.Entity<UserManualCustomer>() 
      .HasKey(t => new { t.CustomerId, t.UserManualId}); 

     builder.Entity<UserManualCustomer>() 
      .HasOne(pt => pt.Customer) 
      .WithMany(p => p.UserManualCustomer) 
      .HasForeignKey(pt => pt.CustomerId); 

     builder.Entity<UserManualCustomer>() 
         .HasOne(pt => pt.UserManual) 
         .WithMany(p => p.UserManualCustomer) 
         .HasForeignKey(pt => pt.UserManualId); 

     base.OnModelCreating(builder); 
    } 
} 

Startup.cs

public class Startup 
{ 
    public const string ConnectionString = @"Server=Server=(localdb)\\ProjectsV13;Database=FSCIDb;Trusted_Connection=true;MultipleActiveResultSets=true"; 

    public Startup(IHostingEnvironment env) 
    { 
     var builder = new ConfigurationBuilder() 
      .SetBasePath(env.ContentRootPath) 
      .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) 
      .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true); 

     if (env.IsDevelopment()) 
     { 
      builder.AddUserSecrets(); 
     } 

     builder.AddEnvironmentVariables(); 
     Configuration = builder.Build(); 
    } 

    public IConfigurationRoot Configuration { get; } 

    public void ConfigureServices(IServiceCollection services) 
    { 
     services.AddDbContext<ApplicationDbContext>(options => 
      options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); 

     services.AddIdentity<ApplicationUser, IdentityRole>() 
      .AddEntityFrameworkStores<ApplicationDbContext>() 
      .AddDefaultTokenProviders(); 

     services.AddMvc(); 

     services.AddScoped<IRepository, Repository>(); 
     services.AddTransient<IEmailSender, AuthMessageSender>(); 
     services.AddTransient<ISmsSender, AuthMessageSender>(); 
    } 

    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) 
    { 
     loggerFactory.AddConsole(Configuration.GetSection("Logging")); 
     loggerFactory.AddDebug(); 

     if (env.IsDevelopment()) 
     { 
      app.UseDeveloperExceptionPage(); 
      app.UseDatabaseErrorPage(); 
      app.UseBrowserLink(); 
     } 
     else 
     { 
      app.UseExceptionHandler("/Home/Error"); 
     } 

     app.UseStaticFiles(); 

     app.UseIdentity(); 

     app.UseMvc(routes => 
     { 
      routes.MapRoute(
       name: "default", 
       template: "{controller=Home}/{action=Index}/{id?}"); 
     }); 
    } 
} 

答えて

0

[OK]をので、私は、ソートの...問題を解決しました。狂気のチェックとして私は新しいWebプロジェクトを作成し、一度に1つのファイルを追加しました。働いた!私は、ApplicationDbContextクラスとDataフォルダをMigrationsで移動することで他のWebプロジェクトを台無しにしてしまったと思います。だから私はそれをそのまま残します:)

関連する問題