This is a migrated thread and some comments may be shown as answers.

Change code generation template for Init() method

3 Answers 54 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Norbert
Top achievements
Rank 2
Norbert asked on 24 Nov 2011, 05:12 PM
Hello,

I want a way to initialize the created domain objects automatically. Therefore every generated class should have a constructor which calls a method called InitializeClass().
I will use this method for custom initialisation...

Thank you very much and go on with OA - it's wonderful!

regards
Norbert

3 Answers, 1 is accepted

Sort by
0
Ivailo
Telerik team
answered on 28 Nov 2011, 03:49 PM
Hi Norbert,

You are on the right track. In order to insert the method call in the class constructor, you will have to modify the code generation templates. Another option would be to add this constructor in a base class and add the class manually, as shown in this code library sample. In both cases make sure you add the method itself either in the class code generation or in partial classes for all domain classes, otherwise you will of course get compilation errors.

If you want to call the method in the constructor without a base class, we cannot offer you a matching sample, but you can still use the base class project as a pattern. The process of templates modification is described in our dedicated documentation article, where you will find the exact locations of the relevant files.

Do not hesitate to let us know if you need further information.
 

Best wishes,
Ivailo
the Telerik team

Q3’11 of Telerik OpenAccess ORM is available for download. Register for the What's New in Data Tools webinar to see what's new and get a chance to WIN A FREE LICENSE!

0
Norbert
Top achievements
Rank 2
answered on 27 Dec 2011, 02:18 PM
Sorry, I was trying but I can't get bit to run.
No matter where to put the Init() Method call...no constructor found?!!

Could you give me a short tipp, please!!!

Thank you in advance,
Norbert
0
Accepted
Alexander
Telerik team
answered on 29 Dec 2011, 05:11 PM
Hello Norbert,

You can add constructors to the generated persistent classes by editing the Specific.ttinclude file, located at C:\Program Files\Telerik\OpenAccess ORM\dsl2010\CodeGenerationTemplates\CSharp\Includes. At line 133 you will find a method called GenerateClass, which is responsible for generating the code of the persistent classes. You can extend it with a constructor as shown below, I have added comments for the code that I have added:
...
this.GenerateCustomAttributes(codeClass.Attributes);
this.WriteLine(classSignature);
this.WriteLine(classOpenToken);
if (!codeClass.DoubleDerived)
{
  
//Custom code starts here:
#>
public <#= codeClass.Name #>()
{
    InitializeClass();
    ... //Additional custom code
}
  
<#+ //Custom code ends here.
    this.GenerateProperties(codeClass.Properties);
...

Once you see the constructors generated, I believe you will easily manage to generate the rest of the code you want. Just note that you need to save the rlinq file or use the Run Custom Tool command from the rlinq's context menu in order to regenerate the persistent classes.
Hope that helps.

Regards,
Alexander
the Telerik team

Q3’11 of Telerik OpenAccess ORM is available for download. Register for the What's New in Data Tools webinar to see what's new and get a chance to WIN A FREE LICENSE!

Tags
General Discussions
Asked by
Norbert
Top achievements
Rank 2
Answers by
Ivailo
Telerik team
Norbert
Top achievements
Rank 2
Alexander
Telerik team
Share this question
or