"..." cannot implement an interface member because it is not public

c# dbcontext entity-framework

Question

public interface IDatabaseContext : IDisposable {

    IDbSet<MyEntity1> Entities1 { get; set; }

}

public class MyDbContext : DbContext, IDatabaseContext {

    IDbSet<MyEntity1> Entities1 { get; set; }

}

Can't compile due to the following error: http://msdn.microsoft.com/en-Us/library/bb384253(v=vs.90).aspx

This, however, is absurd because the interface is clearly public. What might be going wrong here?

1
10
2/14/2014 3:32:32 PM

Accepted Answer

However, this makes no sence since the interface obviously IS public. What could be the error here?

Not at all, no. Participants in classes areprivate without fail. ThisEntities1 is personal:

public class MyDbContext : DbContext, IDatabaseContext {    
    IDbSet<MyEntity1> Entities1 { get; set; }    
}

Remember that this is distinct frominterface s, the center of everythingpublic make little sense access modifiers, as well. Making the member eitherpublic :

public class MyDbContext : DbContext, IDatabaseContext {    
    public IDbSet<MyEntity1> Entities1 { get; set; }    
}

or implement an explicit interface:

public class MyDbContext : DbContext, IDatabaseContext {    
    IDbSet<MyEntity1> IDatabaseContext.Entities1 { get; set; }    
}
23
2/14/2014 3:40:43 PM

Popular Answer

When a class implements an interface member, It ought to bepublic

Watch: zzz-13 zzz

To implement an interface member, the corresponding member of the implementing class must be public, non-static, and have the same name and signature as the interface member.

public class MyDbContext : DbContext, IDatabaseContext {

    public IDbSet<MyEntity1> Entities1 { get; set; }
}

For further information, visit this response, as @Marc Gravell suggested in a comment.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow