ASP.NET MVC 2 validation LINQ to SQL

Posted by Chino on Stack Overflow See other posts from Stack Overflow or by Chino
Published on 2010-03-23T10:54:17Z Indexed on 2010/03/23 11:03 UTC
Read the original article Hit count: 652

Filed under:
|
|

Currently I have a DataModel object which contains my linq to sql classes(a dmbl file). Currently I use a partial class to validate the incoming input. For example

public partial class User : IEntity
{

    public NameValueCollection CheckModel()
    {
        return GetRuleViolations();
    }

    /// <summary>
    /// Method validates incoming data, by given rules in the if statement.
    /// </summary>
    /// <returns>NameValueCollection</returns>
    private NameValueCollection GetRuleViolations()
    {
        NameValueCollection errors = new NameValueCollection();
        if (string.IsNullOrEmpty(Username))
            errors.Add("Username", "A username is required");
        // and so on
        return errors;
    }

}

Now what I want to try to do is add validation attributes to the fields. For example I want to try to add the required attribute to the field Username instead/in addtion of using the validation I currently have. My question is how can I achieve this because the dmbl file is auto generated. Or maybe it is not possible and should I use a different approach?

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about validation