views:

363

answers:

1

I have been googling this non stop for 2 days now and can't find a single complete, ready to use, fully implemented t4 template that generates DataAnnotations. Do they even exist?

I generate POCOs with the standard t4 templates. The actual database table has metadata that describes some of the validation rules, eg not null, nvarchar(25), etc.

So all I want is a t4 template that can take my table and generate a POCO with DataAnnotations, eg

public class Person
{

[Required]
[StringLength(255)]
public FirstName {get;set}

}

It is a basic and fundamental requirement, surely I can not be the first person in the entire world to have this requirement? I don't want to re-invent the wheel here. Yet I haven't found it after searching high and low for days.

This must be possible (and hopefully must be available somewhere to just download) - it would be criminally wrong to have to manually type in these annotations when the metadata for them already exists in the database.

A: 

According to this blog post, data annotations is being considered for a future version of the T4 POCO Templates.

In this post we will delve into the various possible code generation options for future releases of the POCO template...

  • Data annotations based on model facets – Adds data validation by
    specifying attributes based on model facets like StringLengthAttribute
    (MaxLength facet), RequiredAttribute (Nullable facet), KeyAttribute(Key
    element), etc.
Robert Harvey
I saw that when googling - and it was the closest thing that I found. Even if the official template does not provide this, surely someone else has made a template that does? I dont believe that I am the first person in the entire world to want to do this ...
JK
If you're going to use hypotheticals, here's one: Microsoft says they're going to do it themselves, so everyone else is taking a "wait and see" attitude.
Robert Harvey