Decorating Fields with Attributes

Posts   
 
    
Posts: 48
Joined: 26-Mar-2007
# Posted on: 07-Dec-2007 11:36:14   

I am looking at using EViL http://www.codeplex.com/evil to do some simple validation, is it possible to get the code generator to add the attributes when it writes the classes?

something like:

        /// <summary> The Comment property of the Entity Comment<br/><br/>
        /// </summary>
        /// <remarks>Mapped on  table field: "Comment"."Comment"<br/>
        /// Table field type characteristics (type, precision, scale, length): VarChar, 0, 0, 2147483647<br/>
        /// Table field behavior characteristics (is nullable, is PK, is identity): false, false, false</remarks>
        [ValidateMinLength(1, "Comment must not be empty")]
        public virtual System.String Comment
        {
            get { return (System.String)GetValue((int)CommentFieldIndex.Comment, true); }
            set { SetValue((int)CommentFieldIndex.Comment, value); }
        }

I know you do your own validation, just looking into all the options. And EVil is such a cool name simple_smile

Cheers

--Sam

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 07-Dec-2007 15:16:31   

is it possible to get the code generator to add the attributes when it writes the classes?

Yes, you can modify the code generation templates or use your own ones. But according to which criteria the validation attributes/rules will be written? I guess you have to manually write them in the generated code, or am I missing something here?