What's the best way to Enforce Uppercase on an entity field?

Posts   
 
    
TomDog
User
Posts: 618
Joined: 25-Oct-2005
# Posted on: 12-Mar-2006 23:34:04   

Of course it will be done in the UI but I would like to do it in entity as well The easiest way is to change the setter for the field e.g.

public virtual System.String UserName
{
get
{
...
}
//Generated set { SetNewFieldValue((int)SystemUserFieldIndex.UserName, value); }  
set { SetNewFieldValue((int)SystemUserFieldIndex.UserName, (string)value.ToUpper()); } //Mine
}

But this will presumably be wiped out when the classes are regenerated. I guess it could be done using the validation stuff but I don't want to raise an error if its lowercase just Uppercase it regardless.

Jeremy Thomas
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 13-Mar-2006 09:37:39   

What are you using, selfservicing or adapter?

Frans Bouma | Lead developer LLBLGen Pro
TomDog
User
Posts: 618
Joined: 25-Oct-2005
# Posted on: 13-Mar-2006 20:53:50   

Otis wrote:

What are you using, selfservicing or adapter?

Otis - Its hidden in my Signiture - simple_smile VS 2005 Winforms C#, LLBLGen v1.0.2005.1 - Adapter with remoting

Jeremy

Jeremy Thomas
Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 14-Mar-2006 10:50:44   

If you want to do it on the Entity level you have the following options:

1- if you just want it for saving in the database, you may have it in the validation code, or handle the OnSaveEntity() event.

2- if you want it for good, then I would suggest adding your custom property to the Entity class, which sets the original property as you want. Use this custom property through out your UI.

TomDog
User
Posts: 618
Joined: 25-Oct-2005
# Posted on: 15-Mar-2006 03:36:54   

Walaa wrote:

1- if you just want it for saving in the database, you may have it in the validation code, or handle the OnSaveEntity() event.

OnSaveEntity is to late as I want to do it on field change. As far as I can see the Validate code only allows/disallows a change i.e. I can't actually modify and allow a change e.g this has no effect:


public virtual bool Validate(int fieldIndex, object value)
{
switch ((SystemUserFieldIndex)fieldIndex)
{
case SystemUserFieldIndex.UserName:
   value = ((string)value).ToUpper(); 
   break;

Walaa wrote:

2- if you want it for good, then I would suggest adding your custom property to the Entity class, which sets the original property as you want. Use this custom property through out your UI.

Add something maybe called UpperCasedUserName? Seems like a sledgehammer to crack a nut. Is there anyway to prevent the UI guys using the original field?

What would be ideal is the ability to override the getters and setters but seeing I can't maybe I could use this Event Handler.

/// <summary> Event which is thrown when UserName changes value. Databinding related.</summary>
public event EventHandler UserNameChanged;
Jeremy Thomas
TogasPoon
User
Posts: 42
Joined: 09-Feb-2006
# Posted on: 15-Mar-2006 18:19:41   

I have the exact same question, only I'm useing selfservicing.

Thought I'd piggy back onto this thread instead of starting a new one.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 16-Mar-2006 09:05:18   

OnBeforeEntitySave() will be the best place rather than OnSaveEntity()

Please consult the LLBLGen Pro documentation for a list of available events: Intercepting activity calls Here "Using the generated code -> SelfServicing -> Using the entity classes" And here "Using the generated code -> Adapter -> DataAccessAdapter Functionality"

Also you may check the "EntityBase Members" in the LLBLGen Pro Reference manual for available events.

TomDog
User
Posts: 618
Joined: 25-Oct-2005
# Posted on: 17-Mar-2006 03:51:14   

Thanks for the pointers.

However like I said I'd rather do it when the field changes - otherwise the field will potentially be invalid for a long time - who knows when the change will be persisted to the DB.

However in most likelyhood the entity will be saved pretty soon after the field is set so if worse comes to worse I can settle for uppercase in the OnBeforeEntitySave() event.

Jeremy Thomas
pilotboba
User
Posts: 434
Joined: 05-Aug-2005
# Posted on: 17-Mar-2006 16:10:40   

TomDog wrote:

Thanks for the pointers.

However like I said I'd rather do it when the field changes - otherwise the field will potentially be invalid for a long time - who knows when the change will be persisted to the DB.

However in most likelyhood the entity will be saved pretty soon after the field is set so if worse comes to worse I can settle for uppercase in the OnBeforeEntitySave() event.

You could subclass the entity and override the property.

BOb