sekorev (User)
Posted on: 23-Jun-2008 10:11:38.
|
Hi,
Lets say that i have a car entity.
Code: |
txtModel.Text = "Audi"; txtYear.Text = "1983"; txtSubject.Text = "this is An Info abouT the CAr. "; CarEntity car = new CarEntity();
car.Model = txtModel.Text; car.Year = txtYear.Text; car.Info = txtSubject.Text ;
car.Save();
|
what i want to do is whatever the inputs are convert strings to uppercase before ( or just before) Save() function. ( And also i want to replace some characters like ö >> oe , ü >> ue in german ) is there an easy way to do?
After persisting object in db. MODEL = "AUDI" YEAR = "1983" INFO = "THIS IS AN INFO ABOUT THE CAR"
i use SelfServicing model.
thank in advance
|
|
|
goose (User)
Posted on: 23-Jun-2008 19:47:37.
|
You could use one of those methods:
Code: |
// this is called when a value is set public partial class CarEntity { protected override void PreProcessValueToSet(IEntityField2 fieldToSet, ref object valueToSet) { base.PreProcessValueToSet(fieldToSet, ref valueToSet);
// set to UPPERCASE if (valueToSet != null) { if (fieldToSet.Name == CarFields.Model.Name || fieldToSet.Name == CarFields.Info.Name) { valueToSet = (string)((string)valueToSet).ToUpper(); } } } // this is called right before the entity is saved protected override void OnBeforeEntitySave() { // set to UPPERCASE Model = Model.ToUpper(); Info = Info.ToUpper();
base.OnBeforeEntitySave(); } }
|
|
|
|
sekorev (User)
Posted on: 23-Jun-2008 20:20:29.
|
Hi goose,
I have nearly 60 entities, it is really hard to rewrite them by hand. whenever an entity has string values, automatically convert to upper. Is there any way to do it using templates or some other stuff?
|
|
|
Otis (LLBLGen Pro Team)
Posted on: 23-Jun-2008 20:48:00.
|
Override PreProcessValueToSet in a partial class of CommonEntityBase (that will take 1 override )
|
|
|
sekorev (User)
Posted on: 23-Jun-2008 21:01:38.
|
Hi Otis,
i am too newbie to find it.
in the generated project CommonEntityBase.cs , within the class
protected override void PreProcessValueToSet() {
}
Error 1 'light.EntityClasses.CommonEntityBase.PreProcessValueToSet()': no suitable method found to override C:\Projects\lightNET\light\EntityClasses\CommonEntityBase.cs
i appreciate if you show.
|
|
|
Otis (LLBLGen Pro Team)
Posted on: 23-Jun-2008 22:22:41.
|
It's a method in EntityBase/EntityBase2:
Code: |
/// <summary> /// Method which is meant to be overriden to pre-process a value right before it is set as a field's new value. In general you don't need to override /// this method. By default it's a no-op. /// </summary> /// <param name="fieldToSet">The field to set.</param> /// <param name="valueToSet">The value to set.</param> protected virtual void PreProcessValueToSet( IEntityField2 fieldToSet, ref object valueToSet ) { // nothing }
|
so you should be able to override it.
|
|
|
sekorev (User)
Posted on: 24-Jun-2008 13:38:34.
|
Hi,
I dont know how ,the code works now. Thanks all
Quote: |
in the generated project CommonEntityBase.cs , within the class
protected override void PreProcessValueToSet() {
}
Error 1 'light.EntityClasses.CommonEntityBase.PreProcessValueToSet()': no suitable method found to override C:\Projects\lightNET\light\EntityClasses\CommonEntityBase.cs
i appreciate if you show. |
|
|
|