New Posts New Posts RSS Feed: How to trigger validation on a property in the developer partial class?
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

How to trigger validation on a property in the developer partial class?

 Post Reply Post Reply
Author
as123 View Drop Down
Newbie
Newbie


Joined: 27-Apr-2010
Posts: 30
Post Options Post Options   Quote as123 Quote  Post ReplyReply Direct Link To This Post Topic: How to trigger validation on a property in the developer partial class?
    Posted: 09-Dec-2010 at 1:57pm
         How to trigger validation on a new property (based on a property on the entity model) in the developer class respresenting a DF entity?
 
          For example, how to trigger validation on the "NameCustom" property in the following scenario? Using AddTrigger("NameCustom") does not fire the delegate validation function after hitting the setter for NameCustom (checked using the debugger).  In the verifier collection (during debug), I do see a verifier with TriggerItem set to "NameCustom".
 
       If I set the trigger for "Name", it works fine. Do I need to decorate the developer class or NameCustom property with any attributes so that the VerifierEngine can detect the trigger set for NameCustom?
 
       I could not find any documentation or sample in this regard.
 
          Please let me know if I need to post this as a seperate issue.
 
Thanks
 
 
        /* ...IB.Designer.cs */
        public partial class Employee : Entity
        {
          ....      
          public override string Name 
              get { return PropertyMetadata.Name.GetValue(this); }
              set { PropertyMetadata.Name.SetValue(this, value); }
              }
 
             /* The developer class representing the Employee business object */
 
        public partial class Employee : Entity
        {
          ....      
          public override string NameCustom
              get { /* custom getter based on Name property */ ... ; }
              set { /* custom setter based on Name property */ ... ; }
        }
 
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 10-Dec-2010 at 10:24am
as123;

How are you setting your setter on your NameCustom? If you're setting the setter by using the Name property, the verifier for the Name property should have fired. Is that what you want it to do?

In general, to add a custom property to your partial entity class, you need to decorate the getter and setter of the NameCustom with the PropertyMetaData class as follows:

public partial class PropertyMetadata {
      public static readonly DataEntityProperty<Employee, string> NameCustom =
        new DataEntityProperty<Employee, string>("NameCustom", true, false, ConcurrencyStrategy.None, false, false);
}

public override string NameCustom 
              get { return PropertyMetadata.NameCustom.GetValue(this); }
              set { PropertyMetadata.NameCustom.SetValue(this, value); }

However, it is generally not recommended for a custom property to have a public setter as its function is normally a display only. Therefore, a custom property should always be an extension of an existing property of an entity model and let the validation of that custom property be fired on the existing property.

I hope this make sense.
Back to Top
as123 View Drop Down
Newbie
Newbie


Joined: 27-Apr-2010
Posts: 30
Post Options Post Options   Quote as123 Quote  Post ReplyReply Direct Link To This Post Posted: 10-Dec-2010 at 2:42pm

                  I am setting the getter and setter for 'NameCustom' and property metadata as you have suggested .  If I specify Verifiers to be triggered by 'Name', the specified verifiers are executed, but the  error notification (INotifyDataErrorInfo) does not occur on the silverlight client, if the binding is to the property 'NameCustom'. 

                  So, in my scenario, is it possible to bind to a property (NameCustom) in the develop class, specify validations to be trigged based on the corresponding Designer class property (Name), and have the errors notified on the client after executing the validators?  The reason why I want to bind to NameCustom (public) is because I want to do some custom logic in the setter (of course, will do setting on Name after some custom logic) when UI is bound to NameCustom. There are other situations where I want to directly access the public Name property to bypass the custom logic.

                Is it possible to attach verifiers to properties like NameCustom? Or, should verifiers be always attached to properties on DevForce Entities? Please clarify.

               Thanks.

 



Edited by as123 - 10-Dec-2010 at 2:43pm
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 13-Dec-2010 at 11:38am
as123;

Yes, it's possible. Attached is a ValidationSample.zip. I've added a custom property to the Order entity named "Total" and bind that to both a DataGrid and Textbox. The verifier fires an error if a user enters a value that is not between 0 and 100.

Back to Top
as123 View Drop Down
Newbie
Newbie


Joined: 27-Apr-2010
Posts: 30
Post Options Post Options   Quote as123 Quote  Post ReplyReply Direct Link To This Post Posted: 13-Dec-2010 at 1:50pm
    Thanks for the sample app. I was not setting the metadata properly before.

Edited by as123 - 14-Dec-2010 at 3:03pm
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down