I would like to add a custom attribute to my class properties that have a related navigation entity property. For example, I have a Car class with an EngineId property and the related navigation Engine property.
I would like to decorate EngineId as follows:
[CustomNavigationPropertyName("Engine")]
public virtual int EngineId
{
get;
set;
}
I am in the GenerateProperty(EntityProperty property, EntityClass cls, string currentClassName) tmpl method.
What is the code to check if the property is in an FK association, and, if so, what is the property name for the navigation entity?
Thanks,
Travis
tmpl customizations
Re: tmpl customizations
You can add a custom attribute via the interface of Entity Developer:
a) navigate to Model > Settings > Attributes > select the assembly with the needed attributes and make sure that the required attributes are checked in the window below, press OK
b) select the attribute in the Attributes collection of a particular class property
If you want to modify a template, specify:
1) the name of your model (e.g.: Devart Entity Model, *.edml)
2) the name of the template (e.g.: DbContext template)
a) navigate to Model > Settings > Attributes > select the assembly with the needed attributes and make sure that the required attributes are checked in the window below, press OK
b) select the attribute in the Attributes collection of a particular class property
If you want to modify a template, specify:
1) the name of your model (e.g.: Devart Entity Model, *.edml)
2) the name of the template (e.g.: DbContext template)
-
- Posts: 20
- Joined: Thu 14 Mar 2013 15:39
Re: tmpl customizations
I would prefer to make this change by modifying the template.
I am using "Entity Framework DbContext template for Devart Entity Developer C# code generation" and my model is called Mosaic.edml.
Thanks,
Travis
I am using "Entity Framework DbContext template for Devart Entity Developer C# code generation" and my model is called Mosaic.edml.
Thanks,
Travis
Re: tmpl customizations
Here is the code:travis_thelen wrote: ↑Thu 04 Feb 2021 20:28 What is the code to check if the property is in an FK association, and, if so, what is the property name for the navigation entity?
Code: Select all
foreach (EntityAssociation association in property.ParentClass.Model.Associations) {
foreach (EntityProperty associationProperty in association.Child.Properties) {
if (associationProperty == property) {
#>
[CustomNavigationPropertyName("<#= codeProvider.GetValidIdentifier(association.Parent.Name) #>")]
<#+
}
}
foreach (EntityProperty associationProperty in association.Parent.Properties) {
if (associationProperty == property) {
#>
[CustomNavigationPropertyName("<#= codeProvider.GetValidIdentifier(association.Child.Name) #>")]
<#+
}
}
}
- https://www.devart.com/entitydeveloper/ ... lates.html
- use IntelliSense feature in our T4 Editor (completion list appears when you type the '.' character)
- you can switch to the model in design time to read a description of a particular property in the Properties window
general T4 reference: https://docs.microsoft.com/en-us/visual ... ew=vs-2019 - decompiling
C:\Program Files (x86)\Common Files\Devart\EntityDeveloper\EntityDeveloper.Common.dll
C:\Program Files (x86)\Common Files\Devart\EntityDeveloper\EntityDeveloper.Orm.Common.dll
C:\Program Files (x86)\Common Files\Devart\EntityDeveloper\EntityDeveloper.Orm.EntityFramework.dll
may help you to get acquainted with the needed classes and their functionality