This topic deals with the way model object properties can be declared in the code of templates in the Entity Developer application.
At certain stage of development, the existing properties of model objects might not be sufficient. Using Entity Developer you can extend the property lists for objects in the model. These extended properties are either declared in the template, or defined in the model, and then used in code generation. For example, you can add the Generate property to every class and then exclude some classes from generated code by changing the value of this property in the designer.
1. | In the Model Explorer area, click to expand the Templates node. |
2. | In the Templates node, select a custom template, right-click it and select Open from the drop-down menu. Alternatively, you can double-click the selected editable template to open it. |
3. | Enter an appropriate directive, as shown below. |
For example, to declare an extended property for a class, enter the following directive:
<#@ extended name="Test" type="System.Int32" owner="class"#>
To declare an extended property for a class property, enter the following directive:
<#@ extended name="Test" type="System.Boolean" owner="property"#>
Below is an example how extended properties are declared and used in the template code:
<#
// Empty template for Devart Entity Developer C# code generation.
// Copyright (c) 2008-2019 Devart. All rights reserved.
#>
<#@ template language="C#" #>
<#@ extended name="Load" owner="RelationProperty" type="System.Boolean" default="true" #>
<#
// Settings
output.Extension = ".cs";
output.FileName = model.FileName + "DataLoadOptionsFactory";
#>
using Devart.Data.Linq;
using Domain;
namespace <#=!string.IsNullOrEmpty(model.ContextNamespace) ? codeProvider.GetValidIdentifier(model.ContextNamespace) : codeProvider.GetValidIdentifier(model.Name)#> {
public static class DataLoadOptionsFactory {
public static DataLoadOptions CreateLoadOptions() {
DataLoadOptions loadOptions = new DataLoadOptions();
<#
foreach (Class cls in model.Classes)
foreach (RelationProperty relationProperty in cls.RelationProperties)
if ((bool)relationProperty.GetProperty("Load")) {
#>
loadOptions.LoadWith<<#= cls.Name #>>(c => c.<#= relationProperty.Name #>);
<#
}
#>
return loadOptions;
}
}
}
For more information on the language used in templates, see Template Language.
For more information on how to declare extended properties for model objects through the Model Settings window, refer to Extended Properties.
|
Send feedback on this topic
© 2008 - 2024 Devart. All rights reserved.