开发者

adding validation annotators to model classes when using Linq-to-SQL

开发者 https://www.devze.com 2022-12-25 10:42 出处:网络
How should I开发者_如何学Go add the following attrubute [Required(ErrorMessage=\"...\")] to one of the model properties when my model classes are automatically generated.

How should I开发者_如何学Go add the following attrubute

[Required(ErrorMessage="...")]

to one of the model properties when my model classes are automatically generated.

There is a solution here, but it seems to be working only on Entity Framework


The same solution can be applied for LINQ to SQL. The snippet the article shows for using the MetadataType will use perfectly well with LINQ to SQL generated classes:

[MetadataType(typeof(MovieMetaData))]
public partial class Movie
{
}

public class MovieMetaData
{
    [Required]
    public object Title { get; set; }

    [Required]
    [StringLength(5)]
    public object Director { get; set; }


    [DisplayName("Date Released")]
    [Required]
    public object DateReleased { get; set; }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消