teplas wrote:
Of course we can do that, but it's not efficient for large ORM models.
I expected that I could create a file which consists more or less of one single "user code region" that is retained when generating the model.
Any hints on how to actually do this kind of thing instead of just questioning the purpose?
Generating the files would only save you creating them, but at the same time give the problem that you have files without any code which still need to be maintained (the files to which you don't add any code to). So basically you want to scaffold a lot of files which have no real meaning. I would strongly advice against that. Add the partial class file when you need it, create a separate folder in the generated code project and add the extension classes there. What you want is not recommended, because you end up with generated code someone else has to work with and who might wonder why there are so many files which are empty.
Selfservicing actually has build in what you want: it has a 2-class scenario template set, where the derived class of the entity (CustomerEntity) is meant for user code and the actual entity class (CustomerEntityBase), contains the framework generated code. (this stems from the original design in the time when there was no such thing as a partial class, and this was the only option to offer extensibility) Adding yet another file is overkill.
If you insist on having partial classes generated, you can do so of course: add a templatebindings file with a template which generates an empty partial class for an entity.
You do that in the templatebindings viewer where you create a new templatebindings file and define a templateID<->file binding, the templateid and file are up to you, as long as the file is reachable by the designer (so e.g. inside the folder you've specified as 'additional templates' folder in the project settings.
As your template is very simple, you can use TDL templates. (so blabla.template files). See the SDK docs for details.
When you save the templatebindings file inside the designer, you should 'refresh the code generation meta data' which can be done with the green button on the toolbar or in the tools menu. The templatebindings viewer should now have your templatebindings file listed and when selected you see the templatebinding you defined and the filename likely in red. Double click it will create the file and open it in the editor. Add: (if you chose TDL as template language)
namespace <[RootNamespace]>.EntityClasses
{
public partial class <[CurrentEntityName]>Entity
{
}
}
Then you have to add a task which executes the template. You're using v4.2 so you do that in the code generation configuration dialog, tab 3: there you add a new task which executes your template with the templateID you've given in the template bindings file you've created.
Add a 'SD.Tasks.Base.ConsumeTDLTemplate' task.
Set 'destinationFolder' to [driverShortName]\EntityClasses
Set 'filenameFormat' to [elementName]Entity.partial.[extension]
Set 'failWhenExistent' to true (this is very important, as you want to generate them once)
Set 'templateID' to the templateID you defined in your templatebindings file
Set 'emitType' to allEntities
Save the preset, you should now be able to generate your classes, but again, it's overkill.