Otis wrote:
Both versions pull default values from the DB (if possible, not all db's allow it). They're stored in the target field's 'DefaultValue' property. This value is obtainable in .lpt templates, by traversing the fields in the mapping of the entity you're working on.
The default value is however the exact string in the default value property of the table field. This means that if you call a db function there (e.g. GETDATE()), the default value is (GETDATE()).
In an lpt template, obtain the GroupableModelElementMapping object by calling currentProject.GetGroupableModelElementMapping(entity, _executingGenerator.DriverID).
Then traverse the FieldMappings property which contains FieldMapping instances. The MappedTarget is the db field (view/table field) which contains the DefaultValue property.
As said, not all db's retrieve these values. See the catalog explorer whether your fields have indeed default values retrieved from the db.
thank you Otis,
I created a lpt template, something like:
<% foreach(IFieldElementCore field in entityFields)
{
var fieldMapping = mapping.GetFieldMappingOfField(field);
var targetField = fieldMapping.MappedTarget;
if(targetField.HasDefaultValue) {%>
...
<%}
}%>
Now i can determine if a default value exists for each field, and skip it in validation.
The retrieved value is not usable, because, as you said, is the exact string in SQL Server db.