Example Interface:
public Interface IEntity
Property ID() as Integer
end Interface
I want all my EF objects to implement this interface on there Primary Keys.
Is this possible?
Example Interface:
public Interface IEntity
Property ID() as Integer
end Interface
I want all my EF objects to implement this interface on there Primary Keys.
Is this possible?
Yes, you can. The classes that the designer generates are declared partial. In a seperate source file you can declare additional methods for these classes. You can also declare specific interfaces that are already implemented by the generated class.
/* This is the interface that you want to have implemented. */
public interface ISomething
{
void DoSomething();
}
/* This would be part of the generated class */
partial class PartialClass
{
public void DoSomething()
{
}
}
/* This would be your own extension */
partial class PartialClass : ISomething
{
}
This seems very easy to do in CSharp but in VB you have to specifically declare which Properties/Functions/Subs are Implementing the Interface:
public Property Id() as Integer Implements IEntity.Id
Unfortunately I had to Rip out the designer file and modify the generated properties. I ended up getting rid of the Generated File all together and now keep my Models in separate classes with all of the Attribute mappings.