我有两个使用visual studio 2013的上下文。一个用于IdentityModel,另一个用于主数据库创建的上下文。我遇到的问题是每当我在包管理器控制台中运行update-database时,它都会在两者中创建ApplicationDBContext DB。我的主数据库永远不会被创建,因为它似乎将它视为ApplicationDBContext。我尝试过Enable-Migrations -ContextTypeName DI_MVC.Models.DIDBContext,它不会为DIDBContext类创建主数据库表。我能够在visual studio 2012中做到这一点,而没有创建数据库的问题。那是没有ApplicationDBContext的。对我所做错的任何帮助都将不胜感激。
以下是我的2个代码文件。我创建的正常IdentityModel和我的DIDBContext类。此外,我将显示web.config文件以及数据库连接。在App_Data文件夹中创建了2个.mdf文件,但这两个数据库都包含成员资格表。
using System;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration.Conventions;
namespace DI_MVC.Models
{
public class DIDBContext : DbContext
{
public DIDBContext()
: base("DIDBContext")
{
}
public DbSet<DI_ConnectionStrings_CSI> CSIs { get; set; }
public DbSet<DI_DropDownValues_DDV> DDVs { get; set; }
public DbSet<DI_Types_DIT> DITs { get; set; }
public DbSet<DI_FORM_DIF> DIFs { get; set; }
public DbSet<DI_FormTabs_DFT> DFTs { get; set; }
public DbSet<DFI_FormSections_DFS> DFSs { get; set; }
public DbSet<DI_FormElements_DFE> DFEs { get; set; }
public DbSet<DI_DFE_DFS_DDD> DDDs { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<DI_DFE_DFS_DDD>().HasKey(k => new { k.DDD_DFS_ID, k.DDD_DFE_ID });
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}
}
}
using Microsoft.AspNet.Identity.EntityFramework;
using System;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration.Conventions;
namespace DI_MVC.Models
{
// You can add profile data for the user by adding more properties to your ApplicationUser class, please visit http://go.microsoft.com/fwlink/?LinkID=317594 to learn more.
public class ApplicationUser : IdentityUser
{
public DateTime BirthDate { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection")
{
}
}
}
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-DI_MVC-meohmeohmy.mdf;Initial Catalog=aspnet-DI_MVC-meohmeohmy;Integrated Security=True"
providerName="System.Data.SqlClient" />
<add name="DIDBContext" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-DI_MVC-MainDB.mdf;Initial Catalog=aspnet-DI_MVC-MainDB;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>