CodeSmith Community
Your Code. Your Way. Faster!

Validation Code - Where does it go?

Latest post 05-29-2007 2:33 PM by Devhi0000. 3 replies.
  • 02-21-2007 6:11 PM

    Validation Code - Where does it go?

    I am seeing a lot of messages about overloading the "AddValidationRules()" method but I don't know where it goes? 

    protected override void AddValidationRules()

    {

        base.AddValidationRules();

     

        //Add custom validation rules

    }

     

    I have created a custom class based on an auto generated Entity class (public class Unit : NetTiers.Entities.Unit) but the extra validation rules I implemented are not being called when I save the entity.

    • Post Points: 35
  • 02-21-2007 7:17 PM In reply to

    • bgjohnso
    • Top 10 Contributor
    • Joined on 09-15-2005
    • Spokane, WA
    • Posts 767
    • Points 22,605

    RE: Validation Code - Where does it go?

    You don’t want to create a new class.  In you case, you should see two files for your Unit class: Unit.cs and Unit.generated.cs.  If you look in the second file, you will see the method AddValidationRules and it will contain all of the rules that were added based on your database schema.  This file gets overwritten every time you generate your solution, so you should not make any changes there.  The Unit.cs is only generated once and is where you need to add any custom code (validation rules, new properties, composite properties, etc). 

     

    If you need more information, please let us know.

     

    Ben Johnson
    ------------------------------
     Member of the .NetTiers team
     Visit http://www.nettiers.com
    ------------------------------

    • Post Points: 65
  • 02-22-2007 4:12 PM In reply to

    • kujotx
    • Top 500 Contributor
    • Joined on 08-29-2006
    • Houston, TX
    • Posts 13
    • Points 345

    Re: RE: Validation Code - Where does it go?

    What if Unit might be used by multiple clients with almost certain custom validations on a per client basis?

    Individuals will want to add their own custom validation rules that we don't want to share with the others. I am thinking of creating a client tier of inherited classes for those overrides. Or, can you recommend a better solution?

    Thanks for the great work! 


    kujotx
    • Post Points: 5
  • 05-29-2007 2:33 PM In reply to

    • Devhi0000
    • Not Ranked
    • Joined on 05-29-2007
    • Posts 2
    • Points 10

    Re: RE: Validation Code - Where does it go?

    Hi.

    I have difficult to fire auto the custom validations rules coded in class Customers.cs. I need that the custom validations fires auto when Update is fired from GridView that is linked to the ObjectDataSource. I have see samples like this:

    oCustomers.Validate()
    if (oCustomers.IsValid)
    {....}

    This code runs OK with my custom validations. But i don´t need this schema code, because the Update is fired from GridView to the ObjectDataSource.

    Thanks.

    • Post Points: 5
Page 1 of 1 (4 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems