0

当我使用 的接口时System.Data.Entity.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,而ImageSharingDBdo是在DbContext,所以我认为ImageSharingDBInitializer应该实现的IDatabaseIntializer

但是,.Net 会引发错误:

错误 CS0535:'ImageSharingWithAuth.DAL.ImageSharingDBInitializer' 没有实现
接口成员 System.Data.Entity.IDatabaseInitializer.InitializeDatabase(ImageSharingWithAuth.DAL.ImageSharingDB)'

4

2 回答 2

0

它应该是 In-i-tializeDatabase 但你有 In-tializeDatabase。

于 2013-10-21T04:46:24.583 回答
0

如果您想确保您的类从接口实现所有协定,请在接口名称 ( public class className: interfaceName) 上单击鼠标右键,然后选择实现接口。当然你必须实现生成方法:)

于 2013-10-22T12:41:25.033 回答