会计考友 发表于 2012-8-4 14:06:19

Oracle技术:怎么用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 {
    ///
    /// Table : dbo.LoginPolicy
    /// 登陆策略
    /// 数据实体
    ///
   
   
    public class LoginPolicyEntity {
    ///
    /// 自动编号
    /// dbo.LoginPolicy.PolicyID
    /// 默认值
    ///
    public int PolicyID{
    get;set;
    }
    private int _UnfreezeTime = 30;
    ///
    /// 解冻时间
    /// dbo.LoginPolicy.UnfreezeTime
    /// 默认值((30))
    ///
    public int UnfreezeTime{
    get{
    return _UnfreezeTime;
    }
    set{
    _UnfreezeTime = value;
    }
    }
    private int _MaxFailedCount = 5;
    ///
    /// 最大失败次数
    /// dbo.LoginPolicy.MaxFailedCount
    /// 默认值((5))
    ///
    public int MaxFailedCount{
    get{
    return _MaxFailedCount;
    }
    set{
    _MaxFailedCount = value;
    }
    }

会计考友 发表于 2012-8-4 14:06:20

Oracle技术:怎么用T4模板生成数据实体

private bool? _EnableLoginPolicy = true;
    ///
    /// 是否启用登陆策略
    /// dbo.LoginPolicy.EnableLoginPolicy
    /// 默认值((1))
    ///
    public bool? EnableLoginPolicy{
    get{
    return _EnableLoginPolicy;
    }
    set{
    _EnableLoginPolicy = value;
    }
    }
    private DateTime _CreateTime = new DateTime();
    ///
    ///
    /// dbo.LoginPolicy.CreateTime
    /// 默认值(getdate())
    ///
    public DateTime CreateTime{
    get{
    return _CreateTime;
    }
    set{
    _CreateTime = value;
    }
    }
    ///
    ///
    /// dbo.LoginPolicy.Creator
    /// 默认值
    ///
    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 消息接收者,表变量
    ///
页: [1]
查看完整版本: Oracle技术:怎么用T4模板生成数据实体