Problem description
The fetch specifications are strings, but it is not a good idea to use strings for field names because they can easily change during the development process. In the worst case the program crashes at the enduser during runtime.
Let's assume you want to fetch a particular customer from your database.
You could use the following fetch specification.
FetchSpecification spec = new FetchSpecification();
spec.Qualifier = Qualifier.Format("CustomerId > 0 and CustomerSales > 4711);
Solution
Add the following Velocity draft under the (EntityObject)Base region.
#foreach($attribute in $entity.Attributes)
#if(!$attribute.IsHidden)
public static String _${attribute.ColumnName}_NAME = "$attribute.DotNetName";
#end#end
You can use a fetch specification with constant field names.
FetchSpecification spec = new FetchSpecification(); spec.Qualifier = Qualifier.Format(Customer._CustomerId_NAME + " > 0 and " + Customer._CustomerSales_NAME + " > 4711");
From now on, you will get errors at the design time when you change a field name.
Labels
(None)
