当我使用 的接口时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
,而ImageSharingDB
do是在DbContext
,所以我认为ImageSharingDBInitializer
应该实现的IDatabaseIntializer
。
但是,.Net 会引发错误:
错误 CS0535:'ImageSharingWithAuth.DAL.ImageSharingDBInitializer' 没有实现
接口成员 System.Data.Entity.IDatabaseInitializer.InitializeDatabase(ImageSharingWithAuth.DAL.ImageSharingDB)'