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 done 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?

Answers


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; }

Need Your Help

Combining Rows of Lists in Column containing Integers with Python

python pandas

What would be the most Pythonic way to work with lists containing integers within a pandas dataframe as below? My first objective is to just retrieve a list of all unique values in all of the lists

Spark caching RDD without being asked to

scala apache-spark

As per the Spark documentation, if we don't 'cache' a given RDD, then every time we reference it, the business logic (the graph) behind the RDD gets evaluated. But in practice when I tried this using