下载地址:http://www.downxia.com/downinfo/26449.html#softdown
使用版本:4.6(2014-5-5)
代码生成:
下载安装,启动
选择“数据库类型”为 PostgreSQL,修改“数据库连接字符串”
编辑“数据类型映射文件”(可选)(默认映射文件中的数据类型可能会不全,需要根据需要进行补充)
- 可以先直接生成,在生成目录下的“相关配置”文件夹下查看“没有配置的数据类型映射信息.txt”以确定缺少的数据类型
选择“代码文件输出目录”(可选)
设置“代码命名空间”
选择“生成代码语言类型”(可选)
设置“作者”或“自定义代码头注释”
点击“生成代码”或“选择生成”(可选择数据表进行生成)
代码使用:
打开生成目录下的“相关配置配置说明4.txt”,其中介绍了生成代码的使用方法
在解决方案中创建项目(例如:DAL),添加生成的实体代码和生成的实体基类BaseEntity.cs。
添加引用(“相关配置”文件夹下的dll)
- System.Database.Provider.dll
- System.Database.dll
- System.Database.ORMap.dll
使用三层架构,添加BLL层,创建业务代码。
假设生成的一个实体类为Test,其字段结构为:
字段名称 |
字段类型 |
id |
uuid |
name |
character(50) |
comment |
character(256) |
则可添加如下的业务代码:
using System;
using DAL;
namespace BLL
{
public class TestBLL
{
public Guid Add(string name,string comment)
{
Test test = new Test();
test.id = Guid.NewGuid();
test.name = name;
test.comment = comment;
test.Insert();
return test.id;
}
public TestS GetAll()
{
return new TestS(true);
}
public Test Get(Guid id)
{
Test test = new Test();
test.id = id;
return test.GetEntity();
}
public void Update(Test test)
{
test.Update();
}
public void Delete(Test test)
{
test.Delete();
}
}
}
在UI层调用BLL实现数据库的操作
TestBLL bll = new TestBLL();
bll.Add("test1",""); //插入记录
Guid id = bll.Add("test2",""); //插入记录
TestS tests = bll.GetAll(); //获取全部记录
Test test = bll.Get(id); //获取指定id的记录
test.comment = "comment2";
bll.Update(test); //更新记录
bll.Delete(test); //删除记录