varchar fields and max length

Posts   
 
    
obzekt
User
Posts: 60
Joined: 29-Apr-2004
# Posted on: 23-Jun-2005 16:14:06   

Hello. I would like to ask if there is a method to truncate string fields. If for example you have a Person.LastName field that is defined as varchar(30) and you attempt to set the PersonEntity.LastName property to a longer value, then an ArgumentOutOfRange exception is thrown.

Most of the time that is what we need, but in some cases we may prefer to just store as much as we can, truncating the end. Here's what I currently do:


int maxlen = person.Fields[(int)PersonEntityFieldIndex.LastName].SourceColumnMaxLength;
person.LastName = (name.Length > maxlen) ? name.Substring(0, maxlen) : name;

It would be nice to have that an option on that field, and have the framework truncate the string on the developer's behalf.

Frans, what is your opinion on this? Is that something we can expect added in the future?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 24-Jun-2005 12:38:20   

I typically find this something which should be done in a rule defined in the BL. Though of course this rule could be added/executed from the framework. For 2.0 a rule-framework is planned, so I'll add it to that list.

Frans Bouma | Lead developer LLBLGen Pro
AndersJuul
User
Posts: 11
Joined: 17-Dec-2006
# Posted on: 17-Dec-2006 16:28:46   

Hi there,

I'm using 2.0.0.0 and get exactly the error described by other user. Specifically, my sql server pads the strings with spaces and i would expect this exception to occur quite often, when users inserts characters in a field without clearing it to the end.

When you speak of a rule-framework (which I hope was implemented?), how do i apply it? Just a reference to a topic in the help file will be appreciated. I can't seem to locate it.

Otis wrote:

I typically find this something which should be done in a rule defined in the BL. Though of course this rule could be added/executed from the framework. For 2.0 a rule-framework is planned, so I'll add it to that list.

Chester
Support Team
Posts: 223
Joined: 15-Jul-2005
# Posted on: 17-Dec-2006 19:24:24   

Check out the documentation on Validation and Validators. (Using the generated code -> Field validation and entity validation)