<%--
Name: 数据业务层模板
Author: lizhongxiang
Description: 根据数据库表生成数据业务层
--%>
<%@ CodeTemplate Language="C#" TargetLanguage="C#" Debug="False" Description="Create a list of properties from database table." %>
<%@ Property Name="AssemblyName" Type="String" Optional="True" Category="Context" Description="程序集名称" %>
<%@ Property Name="Author" Type="String" Optional="True" Default="lizhongxiang" Category="Context" Description="编写此模块的作者" %>
<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context" Description="待生成数据业务层的表名" %>
<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %>
<%@ Assembly Name="SchemaExplorer" %>
<%@ Import Namespace="SchemaExplorer" %>
/**
* 名称: <%= this.SourceTable.Name %>Bll
* 作者: <%= Author %>
* 时间: <%= DateTime.Now.ToString("yyyy-MM-dd") %>
* 版本: 1
* 说明: <%= string.IsNullOrEmpty(this.SourceTable.Description) ? this.SourceTable.Name : this.SourceTable.Description %> 数据访问层类
*
* 历史:
* 版本<%= "\t\t"%>时间<%= "\t\t\t"%>修改人<%= "\t\t"%>说明
* 1<%= "\t\t"%><%= DateTime.Now.ToString("yyyy-MM-dd") %><%= "\t\t"%><%= Author %><%= "\t\t"%>创建本文件
*/
using System;
using System.Collections.Generic;
using <%= string.IsNullOrEmpty(AssemblyName) ? this.SourceTable.Database.Name : AssemblyName %>.Model;
namespace <%= string.IsNullOrEmpty(AssemblyName) ? this.SourceTable.Database.Name : AssemblyName %>.Bll
{
/// <summary>
/// <%= string.IsNullOrEmpty(this.SourceTable.Description) ? this.SourceTable.Name : this.SourceTable.Description %> 数据访问层类
/// </summary>
public class <%= this.SourceTable.Name %>Bll
{
/// <summary>
/// 获取数据列表
/// </summary>
/// <returns>返回数据列表</returns>
public List<<%= this.SourceTable.Name %>> GetList()
{
return Bll.Db.Fetch<<%= this.SourceTable.Name %>>();
}
/// <summary>
/// 获取分页数据
/// </summary>
/// <param name="pageIndex">页码</param>
/// <param name="pageSize">每页记录数</param>
/// <returns>返回结果页</returns>
public NPoco.Page<<%= this.SourceTable.Name %>> GetPage(long pageIndex, long pageSize)
{
string sql = "SELECT * FROM [<%= this.SourceTable.Name %>]";
return Bll.Db.Page<<%= this.SourceTable.Name %>>(pageIndex, pageSize, sql);
}
/// <summary>
/// 获取分页数据
/// </summary>
/// <param name="pageIndex">页码</param>
/// <param name="pageSize">每页记录数</param>
/// <param name="sql">待执行的 SQL 语句</param>
/// <returns>返回结果页</returns>
public NPoco.Page<<%= this.SourceTable.Name %>> GetPage(long pageIndex, long pageSize, string sql)
{
return Bll.Db.Page<<%= this.SourceTable.Name %>>(pageIndex, pageSize, sql);
}
/// <summary>
/// 获取分页数据
/// </summary>
/// <param name="pageIndex">页码</param>
/// <param name="pageSize">每页记录数</param>
/// <param name="sql">待执行的 SQL 语句</param>
/// <param name="args">语句中的参数列表</param>
/// <returns>返回结果页</returns>
public NPoco.Page<<%= this.SourceTable.Name %>> GetPage(long pageIndex, long pageSize, string sql, params object[] args)
{
return Bll.Db.Page<<%= this.SourceTable.Name %>>(pageIndex, pageSize, sql, args);
}
/// <summary>
/// 根据主键查找数据
/// </summary>
/// <param name="primaryKey">主键</param>
/// <returns>查找成功返回对应实体</returns>
public <%= this.SourceTable.Name %> FindById(object primaryKey)
{
return Bll.Db.SingleOrDefaultById<<%= this.SourceTable.Name %>>(primaryKey);
}
/// <summary>
/// 插入实体到数据库中
/// </summary>
/// <param name="model">待插入的实体</param>
/// <returns>插入成功返回主键</returns>
public object Insert(<%= this.SourceTable.Name %> model)
{
return Bll.Db.Insert(model);
}
/// <summary>
/// 批量插入实体到数据库中
/// </summary>
/// <param name="models">待插入的实体列表</param>
public void InsertBulk(List<<%= this.SourceTable.Name %>> models)
{
Bll.Db.InsertBulk(models);
}
/// <summary>
/// 根据实体更新数据
/// </summary>
/// <param name="model">待更新的实体</param>
/// <returns>返回更新所影响的行</returns>
public int Update(<%= this.SourceTable.Name %> model)
{
return Bll.Db.Update(model);
}
/// <summary>
/// 根据实体删除数据
/// </summary>
/// <param name="model">待删除的实体</param>
/// <returns>返回删除所影响的行</returns>
public int Delete(<%= this.SourceTable.Name %> model)
{
return Bll.Db.Delete(model);
}
/// <summary>
/// 根据主键删除数据
/// </summary>
/// <param name="primaryKey">主键</param>
/// <returns>返回删除所影响的行</returns>
public int Delete(object primaryKey)
{
return Bll.Db.Delete<<%= this.SourceTable.Name %>>(primaryKey);
}
/// <summary>
/// 根据主键检查数据是否已存在
/// </summary>
/// <param name="primaryKey">主键</param>
/// <returns>返回数据是否已存在</returns>
public bool Exists(object primaryKey)
{
return Bll.Db.Exists<<%= this.SourceTable.Name %>>(primaryKey);
}
}
}