Allowing string fields to truncate instead of throwing exception

Posts   
 
    
AlbertK
User
Posts: 44
Joined: 23-Dec-2009
# Posted on: 15-Sep-2010 18:52:18   

What would be the most elegant way to flag individual entity fields of string type, so that the framework would automatically truncate values instead of throwing an error when string length exceeds maximum?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 16-Sep-2010 07:05:38   
David Elizondo | LLBLGen Support Team
AlbertK
User
Posts: 44
Joined: 23-Dec-2009
# Posted on: 16-Sep-2010 15:43:56   

This is very help full. Thank you. However, if I want to truncate only specific fields of specific entities, is there a good way to decorate those fields with a custom attribute or use custom properties in the designer? What would be your recommendation?

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 16-Sep-2010 17:21:14   

Either of those should work - I'm not sure one of them has any real benefit over the other. I'd go with which ever you are more comfortable using.

Matt

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 17-Sep-2010 12:34:42   

custom properties are stored in a hashtable in the entity (static, so stored once). This is obtainable differently from attributes which are reflection based. So custom properties are easier to obtain.

Frans Bouma | Lead developer LLBLGen Pro
AlbertK
User
Posts: 44
Joined: 23-Dec-2009
# Posted on: 21-Sep-2010 17:25:54   

Thank you very much for your responses. Out of curiosity, is this something that you would consider adding to the framework? For example, if there was AutoTruncate property in the field, by default it would be false and raise an exception (for backward compatibility), but if set to true would instead truncate strings... A usage scenario I have is a parser that reads XML document and creates entities. Some attributes values in XML document are descriptions that could be quite long and I want to capture the first 30 characters because the data is not critical. So, it would be nice to do flag this field in the designer and have the framework auto truncate the string.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 21-Sep-2010 17:50:52   

IF we add it, it's always a global setting, as it otherwise will require meta-data per field. It's also not really difficult to implement: the link David gave above allows you to examine which field it is and if it's a field you want to truncate, truncate the value. that's an easy setup for what you want.

In general, truncating text is a BL level decision, the entity just reports whether a value will fit. Doing this inside the entity might 'hide' the behavior, why some fields throw an exception and others accept a value which is too long.

Frans Bouma | Lead developer LLBLGen Pro