第一步:新建自定义模板

<#@ template language="c#" HostSpecific="True" #>
<#@ output extension= ".cs" #>
<#
TableHost host = (TableHost)(Host);
host.Fieldlist.Sort(CodeCommon.CompareByintOrder);
string identityKey=host.IdentityKey.ColumnName ;
string ClassName =host.TableName;
string ClassNames =host.TableName+"s";
#>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace DAL
{
public class <#= ClassName #>_DAO
{ public static string Insert(<#= ClassName #> objEntity)
{
try
{
HISDataContext db = DatabaseHelper.GetDB();
db.<#= ClassNames #>.InsertOnSubmit(objEntity);
db.SubmitChanges();
}
catch (System.Exception ex)
{
return ex.Message;
}
return string.Empty;
} public static string Update(<#= ClassName #> model)
{
try
{
HISDataContext db = DatabaseHelper.GetDB();
<#= ClassName #> oldEntity = db.<#= ClassNames #>.First(c => c.<#= identityKey #> == model.<#= identityKey #>);
DatabaseHelper.Assign<<#= ClassName #>>(model, oldEntity);
db.SubmitChanges();
return "";
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
} public static string DeleteById(int ID)
{
try
{
HISDataContext db = DatabaseHelper.GetDB();
var rs = db.<#= ClassNames #>.Where(c => c.<#= identityKey #> == ID);
if (rs.Count() > )
{
<#= ClassName #> objKey = rs.First<<#= ClassName #>>();
db.<#= ClassNames #>.DeleteOnSubmit(objKey);
db.SubmitChanges();
}
}
catch (System.Exception ex)
{
return ex.Message;
}
return "";
} public static <#= ClassName #> SelectByID(long ID)
{
try
{
HISDataContext db = DatabaseHelper.GetDB();
var rs = (from a in db.<#= ClassNames #>
where a.<#= identityKey #> == ID
select a).ToList<<#= ClassName #>>();
if (rs.Count() > )
return rs.First<<#= ClassName #>>();
else
return null;
}
catch (System.Exception ex)
{
throw new Exception(ex.Message);
}
} public static List<<#= ClassName #>> SelectAll()
{
try
{
HISDataContext db = DatabaseHelper.GetDB();
var list = (from n in db.<#= ClassNames #>
orderby n.<#= identityKey #> descending
select n).ToList<<#= ClassName #>>();
if (list.Count > )
{
return list;
}
else
{
return null;
} }
catch (System.Exception ex)
{
throw new Exception(ex.Message);
}
} } }

如果你的dao名称就是表名的话 那忽略第二步

第二步:批量修改生成文件名

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO; namespace Tools
{
/*
* kook 动软生成dal 用这个批量修改名称 给表名后边加上_dao
* 例如:t_user.cs-->t_user_DAO.cs
*/
class EditFileName
{
static void Main(string[] args)
{
Console.WriteLine("本程序修改动软生成的dao");
RenameFile(@"D:\CodematicDemo\linq", "_DAO");
Console.WriteLine("操作已完成");
Console.ReadKey();
}
public static void RenameFile(string ParentDir, string stringFront)
{
string[] files = Directory.GetFiles(ParentDir, "*.cs", SearchOption.TopDirectoryOnly);
foreach (string file in files)
{
string filename = Path.GetFileName(file);
string pathname = Path.GetDirectoryName(file);
filename = filename.Substring(,filename.Length-) + "_DAO"+".cs";
FileInfo fi = new FileInfo(file);
fi.MoveTo(Path.Combine(pathname, filename));
}
string[] dirs = Directory.GetDirectories(ParentDir);
foreach (string dir in dirs)
{
RenameFile(dir, stringFront);
}
}
}
}

动软 生成 linq相关DAO的更多相关文章

  1. 动软生成的WCP DAO层模板(不使用接口)

    本实战是博主初次学习Java,分析WCP源码时,学习HibernateTools部分的实战,由于初次接触,难免错误,仅供参考,希望批评指正. 开发环境: Eclipse Version: Photon ...

  2. OracleHelper 动软生成

    using System; using System.Collections; using System.Collections.Specialized; using System.Data; usi ...

  3. 动软生成Model(dapper.common)

    <#@ template language="c#" HostSpecific="True" #><#@ output extension= ...

  4. asp.net+mvc+easyui+sqlite 简单用户系统学习之旅(三)—— 简单登录页面+sqlite+动软代码生成器的使用

    上一节讲到利用easyui的layout.tree.tab和datagrid创建用户管理的页面,注意利用到easyui的页面一定要按顺序添加jQuery和easyUI的.js和.css样式,灵活查看e ...

  5. 动软Model 模板 生成可空类型字段

    动软代码 生成可空类型 <#@ template language="c#" HostSpecific="True" #> <#@ outpu ...

  6. 【动软.Net代码生成器】连接MySQL生成C#的POCO实体类(Model)

    首先是工具的下载地址: 动软.Net代码生成器 该工具官网自带完整教程: 文档:http://www.maticsoft.com/help/ 例子:http://www.maticsoft.com/h ...

  7. CodeMatic动软自动生成Nhibernate

    前两天调查了下自动生成工具MyGeneration和codesmith前一个版本已经不更新了后面一个太高级生成 的代码包含了太多东西,没整明白.不过生成的xmlmapping很强大.所以干脆整合一下c ...

  8. 动软代码生成器 可用于生成Entity层,可更改模板 /codesmith 也可以

    动软代码生成器官方下载地址:http://www.maticsoft.com/download.aspx 教程:http://jingyan.baidu.com/article/219f4bf7dfd ...

  9. C# 嵌入dll 动软代码生成器基础使用 系统缓存全解析 .NET开发中的事务处理大比拼 C#之数据类型学习 【基于EF Core的Code First模式的DotNetCore快速开发框架】完成对DB First代码生成的支持 基于EF Core的Code First模式的DotNetCore快速开发框架 【懒人有道】在asp.net core中实现程序集注入

    C# 嵌入dll   在很多时候我们在生成C#exe文件时,如果在工程里调用了dll文件时,那么如果不加以处理的话在生成的exe文件运行时需要连同这个dll一起转移,相比于一个单独干净的exe,这种形 ...

随机推荐

  1. python中执行shell的两种方法总结

    这篇文章主要介绍了python中执行shell的两种方法,有两种方法可以在Python中执行SHELL程序,方法一是使用Python的commands包,方法二则是使用subprocess包,这两个包 ...

  2. Qt学习之信号与槽(一)

    Qt学习之信号与槽(一) 目录 QT的信号与槽机制 在窗口的UI设计中操作添加信号和槽     QT的信号与槽机制   QT的两种机制 在Qt和PyQt中有两种通信机制: 低级事件处理机制(low-l ...

  3. 015.Linux系统删根数据恢复

    重要声明: 本文档所有思路来自于誉天教育,由本人(木二)在实验环境验证通过: 您应当通过誉天邹老师或本人提供的其他授权通道下载.获取本文档,且仅能用于自身的合法合规的业务活动: 本文档的内容仅供学习交 ...

  4. canvas学习-----画直线

    画布 1.添加canvas标签  可以通过CSS或者JS来设置canvs标签的width,height;Ps: <canvas id="cvs"></canvas ...

  5. 关于css的一些特别用法

    (1)input 怎么设置宽高用style来设置,<input style="width:111px;height:111px">(2)怎么让img和input在同一行 ...

  6. AppleScript脚本学习记录《一》

    tell命令块 tell application "Finder" display dialog "Hello World" end tell 声明变量 set ...

  7. Structured Streaming教程(2) —— 常用输入与输出

    上篇了解了一些基本的Structured Streaming的概念,知道了Structured Streaming其实是一个无下界的无限递增的DataFrame.基于这个DataFrame,我们可以做 ...

  8. AIX上解压缩.tar.Z, .tar.gz, .zip及.tgz

    在AIX上最常见的压缩文件就是.tar檔了,而除了tar文件以外,有时会遇到数据是用其它的压缩文件格式,所以偶顺手整理了一些常见的压缩文件格式,在AIX要怎么解压缩 : ·    .tar.Z fil ...

  9. AngularJS中控制器继承

    本篇关注AngularJS中的控制器继承,了解属性和方法是如何被继承的. 嵌套控制器中属性是如何被继承的? ==属性值是字符串 myApp.controller("ParentCtrl&qu ...

  10. 枚举进程句柄File,Section,Mutant,Timer关闭Mutex句柄实现游戏多开

    原文:http://www.cnblogs.com/Y4ng/archive/2012/09/06/EnumProcessHandle_EnumMutex.html 相信做过游戏多开的朋友就会发现,很 ...