hplloyd wrote:
I find that I have this issue a great deal for a whole host of tables in my ever expanding database.
I have messed around with template studio a bit and have a whole load of files and projects being generated in both lpt and TDL, but I have not come across include templates... I will look into this.
It's easier than you might think up front. If you have a lot of statements to include for a lot of entities, you can make per-entity include files using your own templateid's, so you do this in your file you bind to Custom_EntityAdapterTemplate:
<[If StringValueEquals CurrentEntityName "Customer"]>
<# Customer_Include#>
<[EndIf[>
<[If StringValueEquals CurrentEntityName "Order"]>
<# Order_Include#>
<[EndIf[>
etc...
and in your template set definition, you'll bind Customer_Include to the template in which you'll specify all code which has to be included into the customer entity.
I guess my approach will be to have a large include file that does the same thing for all my tables (for some tables there may be many foreign keys).
If you have code which is the same for all entities, you don't have to surround it with that if statement of course, but just add it to the include template. Also, the text in the template is merged with the template at generation time, so you can use TDL statements in the text in the include template
However initially you thew me a bit there because I assume
<[If StringValueEquals StringValueName "Customer"]>
Should be
<[If StringValueEquals CurrentEntityName "Customer"]>
Yes, my bad, I copied the TDL statement from the SDK docs, forgot to change that name. .
If that is the case then I understand that the following property will be added to the customer entity code and only the customer entity code
public string CountryName
{
get
{
if(_country==null)
{
return string.Empty;
}
else
{
return _country.CountryName;
}
}
}
BUT it is this code that confuses me, what is _country? Obvoiusly it is the related CountryEntity for the customer but when is the _country fetched from the database? are there other _entity objects for all the other foreign keys for a table - where in the generated template are they created?
_country is the private class member which is reserved to hold the related entity 'Country', and it's the private member variable which is used by the CustomerEntity.Country property
. Every field mapped onto a relation will end up as fieldName (camel cased with a '' prefix).
You have to fetch this data with a prefetch path when you're fetching customers.
Finally, I assuyme therefore that if i had an employee entity that had a foreign key to a department entity then I could also add the following block to the same include template:
<[If StringValueEquals StringValueName "Employee"]>
public string DepartmentName
{
get
{
if(_department==null)
{
return string.Empty;
}
else
{
return _department.DepartmentName;
}
}
}
<[EndIf]>
....and so on and so on for each of my foreign keys for each of my tables?
yes.
If so then LLBL is even more brilliant than I thought!!
When this is available in the designer then I assume that I will not need these include templates and all the relevant properties will be generated form me - is that correct?
True. I hope to cram in this feature so you can add a 'related field' field to an entity which returns the value of a 1:1 / m:1 related entity. (also with expressions).
Also, the code generator engines will be changed so that they can handle user regions in the code which are preserved between code generation cycles. This then allows you to add code to the generated code without worrying the code is overwritten.