how do I use mvc data annotations in conjunction with auto generated linqtosql classes
I would like to be able to use DataAnnotations when working with my model, so for instance be able to write stuff like
[DisplayName("Title")]
[StringLength(256)]
public string title { get; set; }
I also want to be able to use the column with linq which has led me so far to adding table and column linq mapping annotations such as
[Column(DbType = "NVarChar(256)", UpdateCheck = UpdateCheck.Never)]
However this seems to be a long winded solution.
I would like to be able to use the auto generated linqtosql class but there doesn't seem to be a clear way to use this in conjunction with data annotations.
From research I have don开发者_运维百科e I have come to the conclusion it is not possible to add the annotations using partial classes, and I don't want to have to create another class just for the annotations and start worrying about mapping the auto generated class manually. I also know it is bad practice to edit the code file of the auto generated class manually.
Is there a nice solution to this?
The best way I found was this http://www.asp.net/mvc/tutorials/validation-with-the-data-annotation-validators-cs
namespace MvcApplication1.Models
{
[MetadataType(typeof(MovieMetaData))]
public partial class Movie
{
}
public class MovieMetaData
{
[Required]
public object Title { get; set; }
精彩评论