PostgreSQL 代码生成工具选择

项目中需要使用支持PostgreSQL的ORM代码生成工具,搜寻了几个常用工具进行了考察,考察的原则是“支持PostgreSQL、易于使用”,最终选择了EntitysCodeGenerate。

考察结果如下:


动软代码生成器


MyGeneration


Keelkit


Gentle.NET

  • 下载地址:http://sourceforge.net/projects/gopf/?source=typ_redirect
  • 使用版本:1.5.0(2013-4-3)
  • 支持数据库:Firebird,Jet,MySQL,PostgreSQL,Oracle,OracleODP,SQLite,SQL Server
  • 参考资料:
  • 存在问题:在编辑GentleBusinessObject.cst文件的SourceTable参数时,无法指定PostgreSQL数据源(可能是需要自己按照GentleBusinessObject.cst文件编写对应的配置。
  • 其他问题:Gentle.NET的使用方式是,先利用CodeSmith等生成最基本的Model(无增删查改的方法),再使用Gentle.Framework.Broker对Model进行增删查改。配置上比较复杂,CodeSmith一次只能生成一个数据表,用起来不太方便。

EntitysCodeGenerate

/******************************************
* 模块名称:实体 role
* 当前版本:1.0
* 开发人员:Administrator
* 生成时间:2015/7/8
* 版本历史:此代码由 VB/C#.Net实体代码生成工具(EntitysCodeGenerate 4.6) 自动生成。
* 
******************************************/
using System;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Xml;
using System.IO;
using System.Text;
using System.Database;
using System.Database.ORMap;
using System.Database.Extend;

namespace ZHD.GIS.Entity
{
    /// <summary>
    /// 实体 role
    /// </summary>
    [Description("Primary:id")]
    [Serializable]
    public partial class role : BaseEntity
    {
        #region 构造函数
        /// <summary>
        /// 实体 role
        /// </summary>
        public role(){}
        /// <summary>
        /// 实体 role
        /// </summary>
        /// <param name="keyValue">主键id对应的值</param>
        public role(object keyValue)
        {
            ListDictionary list = new ListDictionary();
            list.Add("id", keyValue);
            ORMap<BaseEntity> ormap = new ORMap<BaseEntity>(this, this);
            ormap.GetEntity(list);
        }
        /// <summary>
        /// 实体 role
        /// </summary>
        /// <param name="colName">实体字段名</param>
        /// <param name="colValue">实体字段名(colName)匹配相等的值</param>
        public role(string colName, object colValue)
        {
            ListDictionary list = new ListDictionary();
            list.Add(colName, colValue);
            ORMap<BaseEntity> ormap = new ORMap<BaseEntity>(this, this);
            ormap.GetEntity(list);
        }
        /// <summary>
        /// 实体 role
        /// </summary>
        /// <param name="colNames">实体字段名数组</param>
        /// <param name="colValues">实体字段名数组(colNames)匹配相等的值</param>
        public role(string[] colNames, object[] colValues)
        {
            if (colNames.Length == colValues.Length)
            {
                ListDictionary list = new ListDictionary();
                for (int i = 0; i < colNames.Length; i++)
                {
                    list.Add(colNames[i], colValues[i]);
                }
                ORMap<BaseEntity> ormap = new ORMap<BaseEntity>(this, this);
                ormap.GetEntity(list);
            }
        }
        /// <summary>
        /// 实体 role
        /// </summary>
        /// <param name="dbCore">数据库访问核心类DbCore实例(用于DbCore事务)</param>
        /// <param name="colName">实体字段名</param>
        /// <param name="colValue">实体字段名(colName)匹配相等的值</param>
        public role(DbCore dbCore, string colName, object colValue)
        {
            ListDictionary list = new ListDictionary();
            list.Add(colName, colValue);
            ORMap<BaseEntity> ormap = new ORMap<BaseEntity>(this, this);
            ormap.GetEntity(dbCore, list);
        }
        /// <summary>
        /// 实体 role
        /// </summary>
        /// <param name="dbCore">数据库访问核心类DbCore实例(用于DbCore事务)</param>
        /// <param name="colNames">实体字段名数组</param>
        /// <param name="colValues">实体字段名数组(colNames)匹配相等的值</param>
        public role(DbCore dbCore, string[] colNames, object[] colValues)
        {
            if (colNames.Length == colValues.Length)
            {
                ListDictionary list = new ListDictionary();
                for (int i = 0; i < colNames.Length; i++)
                {
                    list.Add(colNames[i], colValues[i]);
                }
                ORMap<BaseEntity> ormap = new ORMap<BaseEntity>(this, this);
                ormap.GetEntity(dbCore, list);
            }
        }
        #endregion

        #region 私有变量
        private string _id = null;
        private string _name = null;
        private string _comment = null;
        #endregion

        #region 公共属性
        /// <summary>
        /// 主键 id(NOT NULL)
        /// </summary>
        [DataObjectField(true)]
        public string id
        {
            set{ _id=value;}
            get{
  return _id;}
        }
        /// <summary>
        /// name(NOT NULL)
        /// </summary>
        [DataObjectField(false)]
        public string name
        {
            set{ _name=value;}
            get{
  return _name;}
        }
        /// <summary>
        /// comment
        /// </summary>
        [DataObjectField(false)]
        public string comment
        {
            set{ _comment=value;}
            get{
  return _comment;}
        }
        #endregion

        #region 常用 增、删、改、查 操作(注:.Net下数值型字段初始值默认为0;带?的数值型字段值默认为null.)

        #region public override int DelInsert/DelInsertEx 扩展方法
        /// <summary>
        ///  先Delete后Insert 比较实体前后默认的初始值,且不插入与实体初始值相同的字段值
        /// </summary>
        /// <returns>先Delete后Insert并返回受影响的行数</returns>
        public override int DelInsert()
        {
            ORMap<BaseEntity> ormap = new ORMap<BaseEntity>(this);
            return ormap.DelInsert(new role());
        }
        /// <summary>
        /// 先Delete后Insert 插入所有字段,其中若与实体字段初始值相同则置该字段为空
        /// </summary>
        /// <returns>先Delete后Insert并返回受影响的行数</returns>
        public override int DelInsertEx()
        {
            ORMap<BaseEntity> ormap = new ORMap<BaseEntity>(this);
            return ormap.DelInsertEx(new role());
        }
        #endregion

        #region public override int Insert 增加
        /// <summary>
        /// 通过实体映射插入表中一条数据,插入与初始值不同的字段
        /// </summary>
        /// <returns>执行插入数据并返回受影响的行数</returns>
        public override int Insert()
        {
            ORMap<BaseEntity> ormap = new ORMap<BaseEntity>(this);
            return ormap.Insert(new role());
        }
        #endregion

        #region public override int Update 更新
        /// <summary>
        /// 通过实体映射及主键约束更新表中一条数据,并与比较实体初始值比较,若内容不同则更新之,否则不更新(并与实体默认初始值比较确定更新哪些字段,与默认初始值一样的字段将不更新)
        /// </summary>
        /// <returns>执行更新并返回受影响的行数</returns>
        public override int Update()
        {
            ORMap<BaseEntity> ormap = new ORMap<BaseEntity>(this);
            return ormap.Update(new role());
        }
        #endregion

        #region public override int Save 保存 规则:按主键判断有就更新,没有就插入,且不保存与实体初始值相同的字段值
        /// <summary>
        /// 保存 比较实体前后的值,若有与主键记录相同的就更新,没有就插入,且不保存与实体初始值相同的字段值
        /// </summary>
        /// <returns>执行更新或插入数据操作并返回受影响的行数</returns>
        public override int Save()
        {
            ORMap<BaseEntity> ormap = new ORMap<BaseEntity>(this);
            return ormap.Save1(new role());
        }
        #
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值