當我使用System.Data.Entity.IDatabaseIntializer
的接口時,它總是說它沒有實現接口。不實現IDatabaseIntializer的接口
namespace ImageSharingWithAuth.DAL
{
public class ImageSharingDB : DbContext
{
public DbSet<Image> Images { get; set; }
public DbSet<User> Users { get; set; }
public DbSet<Tag> Tags { get; set; }
public ImageSharingDB() : base("DefaultConnection") { }
}
}
namespace ImageSharingWithAuth.DAL
{
public class ImageSharingDBInitializer : IDatabaseInitializer<ImageSharingDB>
{
public void IntializeDatabase(ImageSharingDB db)
{
if (db.Database.Exists())
{
db.Database.ExecuteSqlCommand("alter database ImageSharingWithAuth set single_user with rollback immediate");
db.Database.Delete();
}
db.Database.Create();
WebSecurity.InitializeDatabaseConnection(
"DefaultConnection",
"Users",
"Id",
"UserId",
autoCreateTables: true);
this.Seed(db);
}
protected void Seed(ImageSharingDB db)
{......
接口應該是System.Data.Entity.IDatabaseIntializer<in TContext>
其中TContext: DbContext
和ImageSharingDB
做的是DbContext
,所以我認爲ImageSharingDBInitializer
應實施IDatabaseIntializer
。
然而,淨拋出一個錯誤:
error CS0535: 'ImageSharingWithAuth.DAL.ImageSharingDBInitializer'does not implement
interface member System.Data.Entity.IDatabaseInitializer.InitializeDatabase(ImageSharingWithAuth.DAL.ImageSharingDB)'