2

I'm using Entity Framework Power Tools Reverse Engineer Code First to generate my poco classes, mapping files, and context from the database. I would also like for this process to create my base partial Validation classes for each entity. I am fine with writing the t4 template, but is there a way I can shoehorn that into the process when I run the Reverse Engineer Code First process?

Mike Cole
  • 14,474
  • 28
  • 114
  • 194

2 Answers2

2

I may be misunderstanding your question, but if not, one way to do it is to add the code to Entity.tt and have your class files include both the POCO class and your validation class. It's generated code that you shouldn't have to be referencing much if at all outside of intellisense in the calling code.

Alternatively maybe you could add a new validation class generating .tt file to the ReverseEngineerCodeFirst folder, but I haven't tried it and it wouldn't surprise me if running ReverseEngineer Code First would not actually run it.

EGP
  • 616
  • 5
  • 11
  • Adding it to the Entity.tt file is what I ended up doing. I checked the source code and it seems to be looking distinctly for those 3 files. It might be a good idea to have it work like you say where it picks up all *.tt files in that folder. – Mike Cole Nov 19 '13 at 15:19
  • Yeah, the Reverse Engineering actually stinks IMNSHO. I threw three hours at writing a homegrown version of it recently and got pretty close before I had to give up and move on to other things. – EGP Nov 26 '13 at 13:01
  • It works pretty well for me. There's just a few limitations you have to work around. – Mike Cole Nov 26 '13 at 15:13
0

I recently customized the Entity Framework PowerTools to produce an interface for the model context. For this purpose, I added an Interface.tt template. You can review my changes at https://entityframework.codeplex.com/SourceControl/network/forks/khawajaumarfarooq/PowerToolEnhancements.

The source code does have to be modified to add extra templates to be processed when reverse engineering POCO classes.

The source code would also have to be modified if you want to generate additional files and have them be included in the project programmatically, as opposed to adding them in yourself after code generation is complete.

Umar Farooq Khawaja
  • 3,925
  • 1
  • 31
  • 52