2013-10-21 77 views
0

當我使用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: DbContextImageSharingDB做的是DbContext,所以我認爲ImageSharingDBInitializer應實施IDatabaseIntializer

然而,淨拋出一個錯誤:

error CS0535: 'ImageSharingWithAuth.DAL.ImageSharingDBInitializer'does not implement
interface member System.Data.Entity.IDatabaseInitializer.InitializeDatabase(ImageSharingWithAuth.DAL.ImageSharingDB)'

回答

0

它應該是IN-I-tializeDatabase但你必須在-tializeDatabase。

0

如果您想確保您的課程從界面執行所有合同,請在界面名稱(public class className: interfaceName)上單擊右鍵並選擇實施界面。當然你必須執行生成方法:)