How to set a field value to lowercase in Entity

Posts   
 
    
can1
User
Posts: 77
Joined: 16-Sep-2005
# Posted on: 11-Nov-2008 16:57:29   

Hello,

I have a string field that I always want to force to lowercase, regardless of the case that the user entered.

I have tried overriding the OnSetValue method using a partial class:


    /// <summary>
    /// Entity class which represents the entity 'MerchantStorePageSeoNames'.<br/><br/>
    /// 
    /// </summary>
    public partial class MerchantStorePageSeoNamesEntity : CommonEntityBase, ISerializable
    {
        protected override void OnSetValue(int fieldIndex, object valueToSet, out bool cancel)
        {
            
          base.OnSetValue(fieldIndex, valueToSet, out cancel);

            if (fieldIndex == (int)MerchantStorePageSeoNamesFieldIndex.SeoFriendlyName)
            {
                valueToSet = (object)valueToSet.ToString().ToLower();
                this.Fields[fieldIndex].ForcedCurrentValueWrite(valueToSet);
            }
        }

    }

When I set the entity field, ie. entityVar.SeoFriendlyName = "LLBLRocks"; , the code enters this overridden method. The value of the SeoFriendlyName property at the end of the procedure is correct, "llblrocks", but once it exits to the calling procedure, it is upper case again.

Does anyone have any suggestions on how to achieve this within the entity itself?

Thanks.

Can1

can1
User
Posts: 77
Joined: 16-Sep-2005
# Posted on: 11-Nov-2008 21:01:05   

I found a solution in the following post:

http://llblgen.com/tinyforum/Messages.aspx?ThreadID=11625&HighLight=1

The

protected override void PreProcessValueToSet(IEntityField2 fieldToSet, ref object valueToSet)

and

protected override void PostProcessValueToGet(IEntityField2 fieldToGet, ref object valueToReturn)

methods let me alter the values as required and do not run into the recursive issue that I was having with some of the ways I was trying to use in getting OnSet working.

Can1

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 11-Nov-2008 21:19:17   

Thanks for updating your own issue simple_smile