public interface IDatabaseContext : IDisposable {
IDbSet<MyEntity1> Entities1 { get; set; }
}
public class MyDbContext : DbContext, IDatabaseContext {
IDbSet<MyEntity1> Entities1 { get; set; }
}
Can't compile because of the error described in here: http://msdn.microsoft.com/en-Us/library/bb384253(v=vs.90).aspx
However, this makes no sence since the interface obviously IS public. What could be the error here?
The error thrown is usually “Cannot implement an interface member because it is not public”. If an interface member method is implemented in your class without an access modifier, it is by default private. To change the visibility, you can either change the interface from public to internal.
An interface only has declarations of methods, properties, indexers, and events. An interface has only public members and it cannot include private, protected, or internal members.
1) Interface members are only visible to code outside of the interface based on the rules of the respective visibility level. public : Interface members in C# are public by default, so this works.
Interface can contain declarations of method, properties, indexers, and events. Interface cannot include private, protected, or internal members. All the members are public by default. Interface cannot contain fields, and auto-implemented properties.
When implementing an interface member in the class, it should be public
See: Interfaces (C# Programming Guide)
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; }
}
Or as @Marc Gravell said in comment you can do Explicit interface implemenation, More could be found at this answer
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With