哪里可以找到数据注释实体框架T4模板? [英] Where are the Entity Framework t4 templates for Data Annotations?

查看:153
本文介绍了哪里可以找到数据注释实体框架T4模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在谷歌上搜索,现在2天本不停止,不能找到一个完整的,随时使用,全面实施T4模板生成DataAnnotations。难道他们甚至还存在?

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?

我生成标准的T4模板波苏斯。实际的数据库表有介绍了一些验证规则,如不为空,为nvarchar(25)等元数据。

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.

因此​​,所有我想要的是可以把我的表,并生成一个POCO T4模板的的DataAnnotations,如:

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.

推荐答案

这里是你想要的!

T4元数据和数据注释模板

T4 Metadata and Data Annotations Template

本T4模板处理从实体生成的元数据类
  Framework 4的模型和装饰数据注释属性
  属性,如[必需]和[StringLength]。在[数据类型]
  属性也被施加在适当的时候。它也将产生
  为必填项基于属性名称的ErrorMessage值。

This T4 template handles generating metadata classes from an Entity Framework 4 model and decorates properties with data annotation attributes such as [Required] and [StringLength]. The [DataType] attribute is also applied when appropriate. It'll also generate ErrorMessage values based upon property names for required fields.

这篇关于哪里可以找到数据注释实体框架T4模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆