I have an existing SQL Database in which all tables have an ID column as the primary key. Can I generate an Entity Framework Model from this database AND make sure all the generated types inherit from an interface that defines the ID property?
Basically, I want everything that I return from the database to implement this:
public interface IDatabaseTable
{
public int ID { get; set; }
}
I hope you using EntityFramework 4 if so you need to use T4 templates to generate your entity and data context, you may download that from here
http://visualstudiogallery.msdn.microsoft.com/23df0450-5677-4926-96cc-173d02752313
Than when you get it setup you would need to modify T4 template to generate inheritance.
So you would get two tamplates one template which is generating Data Context and other one which is generating Entities.
You need to modify the second one(entity generator template), go to line 41 of your entity .tt file and add your inheritance there like that:
Some details on T4 POCO tamplates you may find here
http://sharedtolearn.blogspot.com/2010/06/entity-framework-40-and-t4-templates-to.html
http://msdn.microsoft.com/en-us/data/gg558520