我不明白为什么我的代码不起作用。我有一个模特:
public class Client
{
public int Id { get; set; }
public string Surname { get; set; }
}
我有一个上下文:
public class BetContext : DbContext
{
public BetContext()
: base("name=Bet")
{
}
public virtual DbSet<Client> Clients { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}
}
我的ConnectionString:
<connectionStrings>
<add name="Bet" providerName="System.Data.SqlClient" connectionString="Data Source=PK01; Initial Catalog=Bet;Integrated Security=True; MultipleActiveResultSets=True" />
</connectionStrings>
我的GlobalAsax:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
ControllerBuilder.Current.SetControllerFactory(new NinjectControllerFactory());
Database.SetInitializer(new InitializerDb());
}
我的ConnectToServer: ConnectToServer
我的初始化程序:
public class InitializerDb : DropCreateDatabaseIfModelChanges<BetContext>
{
protected override void Seed(BetContext context)
{
var client = new List<Client>
{
new Client
{
Id = 1 , Surname = "Lalala" , Name = "Paxan" , DateOfBirthday = DateTime.Now, Email = "lalll",
Password = "123445" , Phone = "12345"
}
};
client.ForEach(s => context.Clients.Add(s));
context.SaveChanges();
}
}
我被困住了。请告诉我为什么这段代码没有在SQL Server中创建新数据库?