the fields in an entity have to be mapped in the EDMX file, so they have to be mapped before code generation starts.
You could do the following: abuse the element search feature. It'll execute all code you enter over the model, so you can do the following (in a search for entities for example) (the code below is sloppy, it's only for illustration purposes.
- for each entity in the model
- if it doesn't have a field called 'CreatedBy'
-
do :
var f= e.Fields.AddNew();
f.Name = 'CreatedBy';
f.FieldType = p.TypeShortcuts.FirstOrDefault(t=>t.Shortcut=="string");
- do this also for the other fields you want.
It might be wise to do this inside a non-undoable period:
CommandQueueManagerSingleton.GetInstance().BeginNonUndoablePeriod();
var saveRaiseEvents = CommandQueueManagerSingleton.GetInstance().RaiseEvents;
CommandQueueManagerSingleton.GetInstance().RaiseEvents = false;
try
{
// your code
}
finally
{
CommandQueueManagerSingleton.GetInstance().RaiseEvents = saveRaiseEvents;
CommandQueueManagerSingleton.GetInstance().EndNonUndoablePeriod();
}
and then at the end return an object to satisfy the search.
You can also create a simple plugin which does this.
After the fields are added, right click 'entities' in project explorer and execute the 'automap unmapped fields ' feature to create table fields if necessary and create the proper mappings.