views:

627

answers:

2

The problem I'm having is, using the POCO templates, generating my POCO classes the first time only and not overwriting them when the templates are re-ran. I know this sounds hokey and the reason is that I'm actually changing these templates and trying to generate metadata classes rather than the actual POCO classes, but these metadata classes will be hand-edited and I want to keep those edits in the future but still regenerate a certain amount of it. I have it all working exactly as I want except for the regeneration of the files.

I have looked into T4 and it seems that there is a flag to do just this (see the Output.PreserveExistingFile property) but I don't understand where/how to set this flag. If you can tell me where/how to set this in the default POCO templates, then I think that's all I really need.

Thanks!! :-)

+1  A: 

PreserveExistingFile property is only available in T4 Toolbox. POCO templates are plain T4, someone would have to convert them. Any volunteers?

Oleg Sych
This shows my ignorance as to what T4 and T4 Toolbox are. :-P So is this a large task?
Jaxidian
It would be straigtforward. EF templates lump all classes in a single .tt file. T4 Toolbox separates them into separate .tt files/template classes. Ping me if you are interested.
Oleg Sych
+1  A: 

You're doing this wrong.

All the classes created are partial classes. If you wish to alter the templates create new partial classes and put your code in them.

Will
Can't do that with metadata attributes. I need to add attributes to the properties themselves and the properties I want to add the attributes to are code-generated. But even still, I want a certain amount of this pre-generated for me the first time through (i.e. when I create a new DAL for a DB with ~150 tables I'd like the "Required" attribute to be there for the NotNull columns, numeric for int columns, etc.). The more complex validations we'll add by hand but if we can code-gen the trivial things, it will save a lot of time. And why not keep it around for new tables too??
Jaxidian
As for the actual model itself, I want it to ALWAYS stay in sync with my edmx that defines the model so those I want to always re-generate.
Jaxidian