我有以下代码:
public DataInitializer() {
Database.SetInitializer<DataContext>(null);
try {
using (var context = new DataContext()) {
if (!context.Database.Exists())
{
((IObjectContextAdapter)context).ObjectContext.CreateDatabase();
}
}
}
catch (Exception ex) {
throw new InvalidOperationException("The Data database could not be initialized", ex);
}
}
和
public class DataContext : DbContext
{
public DataContext() : base("xxdata") { }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}
public DbSet<Application> Applications { get; set; }
}
当我逐步执行代码时,代码会被执行,但似乎没有创建数据库文件(SQL Server Express)。
有什么明显的我做错了吗?