I’m basically re-asking this question as the only and accepted answer is not an answer to the question.
Is it possible to tell EF to use a class that subclasses EntityObject, like the one below, as the base class of generated entity classes?
public abstract class CustomEntityObject : EntityObject
{
<additional functionality>
}
The reason I’m asking is I want to stop adding interfaces and implementing them on all entity types in separate partial class files. By sub-classing EntityObject I could implement the additional functionality once only.
Update:
EF implicitly uses a .tt file to generate entity classes. By implicitly I mean you don’t see the .tt file in your project. The solution is to add the template explictly (right-click on the .edmx designer and click “Add Code Generation Item…”, then add “ADO.NET EntityObject Generator”). You then change a single value in the .tt:
string BaseTypeName(EntityType entity, CodeGenerationTools code)
{
return entity.BaseType == null ? "EntityObject" : MultiSchemaEscape((StructuralType)entity.BaseType, code);
}
changes to:
string BaseTypeName(EntityType entity, CodeGenerationTools code)
{
return entity.BaseType == null ? "CustomEntityObject" : MultiSchemaEscape((StructuralType)entity.BaseType, code);
}
Thing is, that using default T4 template designer will generate entity classes inherited from EntityClass.
To use model designer and have ability to supply custom base class you need to download http://msdn.microsoft.com/en-us/library/ff477605.aspx (it’s a description how to use it, before it was in add item>online templates, but at least on my vs2012 can’t find it anymore, it tmay be that is gone for a reason) template and edit template files to inject your custom base class, but I think that most of programmers look at POCO for a reason, so may be better idea is to have classes that don’t have persistence attached.