t4模板生成html,如何用T4模板生成数据实体

我们现有的项目没有采用任何ORM,所有的数据读取与操作都是基于存储过程的,在代码端使用 Enterprise Library 5 。 在 EntLib 和数据库之间,是基于我原来写的一个 T4 实体生成的模板,之前也没有详细的去整,反正能运行出结果就行了,总之,代码很乱。

较近一期项目告一段落,后续项目还没有上马,一手把这个部门建立起来的总监(经理)又离开了这个团队,我们几个老一批的员工也在思索着是否换换。趁着这个便当,我把这个东西在整出来,算是给我增加一个砝码吧。

什么是 T4 模板,自己去搜吧,怎么用也请自己搜吧。懂就懂,不懂我也懒得解释。

我将要贴出的T4模板是将 SQLServer 2008 的 Table, View , TableType, Procedure 解析为 C# 里的对应实体,形如下:

Table/View/TableType

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Data;

using System.Collections;

using System.ComponentModel;

using System.Runtime.Serialization;

namespace AsNum.MySecret.Entity.Database {

///

[Serializable]

[DataContract]

public class LoginPolicyEntity {

///

public int PolicyID{

get;set;

}

private int _UnfreezeTime = 30;

///

public int UnfreezeTime{

get{

return _UnfreezeTime;

}

set{

_UnfreezeTime = value;

}

}

private int _MaxFailedCount = 5;

///

public int MaxFailedCount{

get{

return _MaxFailedCount;

}

set{

_MaxFailedCount = value;

}

}

private bool? _EnableLoginPolicy = true;

///

public bool? EnableLoginPolicy{

get{

return _EnableLoginPolicy;

}

set{

_EnableLoginPolicy = value;

}

}

private DateTime _CreateTime = new DateTime();

///

public DateTime CreateTime{

get{

return _CreateTime;

}

set{

_CreateTime = value;

}

}

///

public string Creator{

get;set;

}

}  } Procedure

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Data;

using System.Collections;

using System.ComponentModel;

using System.Data.SqlClient;

using Microsoft.Practices.EnterpriseLibrary.Data;

using AsNum.MySecret.Entity.Database;

using AsNum.Common.Extend;

namespace AsNum.MySecret.DB

{

///

///

///

public partial class SPs {

///

/// 发送消息

///

///

/// @Title 消息标题

/// @Ctx 消息内容

/// @UserID 用户ID

/// @FromIP 发消息的IP

/// @IntranetIP 发消息的内网IP,用于扩展

/// @IsPublic 是否公开

/// @Receiver 消息接收者,表变量

///

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值