MVC.net +亚音速自动生成TT元数据类 [英] MVC.net + subsonic Auto Generate MetaData Classes from TT

查看:194
本文介绍了MVC.net +亚音速自动生成TT元数据类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不是一个问题,但我没有一个博客,我刚刚创建了一个新的亚音速TT文件
将自动生成的元数据类亚音速类,所以你可以
使用dataAnnotation和CreateForModel等时跳过一些工作

Not a question but i dont have a blog and i have just created a new subsonic TT file that will generate the Metadata classes automatically for the subsonic classes so you can skip out some work when using dataAnnotation and CreateForModel etc

所以第一步是修改您的ActiveRecord.TT以下

so the first step is to amend your ActiveRecord.TT with the following

using System.ComponentModel; 
using System.Data.Common; 
using System.ComponentModel.DataAnnotations;

然后在类名的上面的一代,我们需要对我们的元数据的引用
像这样:

Then above the generation of the class name we need to make a reference to our metadata like so:

[MetadataType(typeof(<#=tbl.ClassName#>MetaData))]
public partial class <#=tbl.ClassName#>: IActiveRecord

这就是一切完成ActiveRecord.tt

thats everything completed for ActiveRecord.tt

现在您MetaGenerator TT低于,发现我的包括是MySQL
你将需要修改这一行要占你的数据库类型

now your MetaGenerator TT is below, notice that my include is for MySql you will need to amend this line to account for your DB type

<#@ include file="MySQL.ttinclude" #>  
using System;  
using System.ComponentModel;  
using System.ComponentModel.DataAnnotations;  

namespace <#=Namespace #>  
{  
<#  
var tables = LoadTables();  
foreach(Table tbl in tables)  
{  
if(!ExcludeTables.Contains(tbl.Name))  
{  
#>  
public class <#=tbl.ClassName#>MetaData  
{  
<# foreach(Column col in tbl.Columns)  
{  
if (tbl.ClassName == col.CleanName)  
{  
col.CleanName += "X";  
} #>    
[DisplayName("<#=col.CleanName #>: ")]   
<# if(String.IsNullOrEmpty(CheckNullable(col))) { #>  
[Required(ErrorMessage = "<#=col.CleanName #> is a required element.")] <# }      
#>          
public <#=col.SysType #><#=CheckNullable(col)#> <#=col.CleanName #>  { get;set; }  
<#    
}   
#>  
}  
<# }  
} #>   
}  

我添加了一个小检查,看是否该项目可为空或没有,如果没有的话我加入
一个必需的元素。

I have added a small check to see if the item is nullable or not, if not then i am adding a required element.

现在这个并不光彩,但它会说,相当多的工作,为大型数据库
并采用editorFor等是敲出来的网页,甚至没有思考它辉煌之路。

now this is not brilliant, but it would say quite a bit of work for a large database and using editorFor etc is a brilliant way to knock out pages without even thinking about it.


元数据类而不是亚音速类,一切都那么飞机航行

when creating a strongly type view for a create or edit i make reference to the MetaData class rather than to the subsonic class and everything is then plane sailing

添加到您自己的自定义编辑codeTemplates,你真的没有做太多
对事物的HTML端,一旦你有一个母版页创建的。

add this to your own custom edited CodeTemplates and you dont really have to do much on the Html side of things once you have a master page created.

反正喜欢我敢肯定它会为一个人是有用的!

anyway enjoy im sure that it would be useful for one person!

推荐答案

做了一个更好的版本的这个到这里的文档
亚音速TT扩展为亚音速巴迪班

have done a better version of this onto the docs here Subsonic TT Extension for Subsonic Buddy Classes

这篇关于MVC.net +亚音速自动生成TT元数据类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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