eugene wrote:
I guess the ability to merge code needs not to be considered as essential. (maybe a great nice-to-have).
First it is quite problematic to get things right while merging files. Also, maybe it is not needed after all, should you be able to seperate generated and user code in seperate files (self-servicing is a great example of this!). This should be easier with .NET 2.0.
What the plan is is that in the template regions are defined for user code. When emitting the code, an exisiting file is read, the same regions are read and copied over to the text to write, which effectively means the code you write in these regions is preserved between code generation. I think that's the main point, and would release you from the burdon of keeping track of your own code.
I didn't understand the solution you describe in your posting.
<[If StringValueEquals CurrentEntityName "Order"]>
<# OrderEntityInclude #>
<[EndIf]>
Take for example the entity CustomerEntity with the properties Name and Surname. In MyCustomerEntity I would write a property, FullName that returns a concatanation of Name and Surname while considering some rules.
Now assume the table Customer in the DB is modified by adding a new relationship to table Discounts. This would need to be reflected in the MyCustomerEntity (Prefetch and Members).
Would using the include template you mention save my user code, while appending the generated code?
You write your FullName property in the template customerInclude.template for example. Then you define an include file for the entities (as one template is included in the entity template). This is simply a template with solely
<[If StringValueEquals CurrentEntityName "Order"]>
<# OrderEntityInclude #>
<[EndIf]>
statements, so in your case thus also:
<[If StringValueEquals CurrentEntityName "Customer"]>
<# CustomerEntityInclude #>
<[EndIf]>
Now, you have to create a new templateset config based on an existing one where you ADD the template bindings of for example CustomerEntityInclude, and also the binding of Custom_EntityAdapterTemplate, which is the ID of the template to include in each entity class.
Now, Custom_EntityAdapterTemplate you bind to the template with the <[If StringValueEquals... statements. CustomerEntityInclude you bind to a file, for example the mentioned, customerInclude.template, which contains:
public string FullName
{
get { return this.FirstName + " " + this.LastName; }
}
When you then generate your code, the code generator will first merge the template customerInclude.template into the template you bound to Custom_EntityAdapterTemplate, at the spot <# CustomerEntityInclude #> (thus still surrounded by the ifstatement). Then, that merge result is merged with the template for adapter entities at the spot where Custom_EntityAdapterTemplate is included (at the bottom). THEN the template is ran. For customer entities only the statement <[If StringValueEquals CurrentEntityName "Customer"]> will be true, so only in customer templates, the contents of customerInclude.template is emitted into the output stream (and thus ending up in your customer entity code file
).
This way you can control which code goes in which entity and you don't have to work with a large file. To develop this kind of code, first write the code you want to emit into the generated code, compile it, then go to templatestudio and create a template and copy over the code, in this case the property of Fullname.
Thank you in advance for your reply and have a nice weekend!
You too!