数据库教程:codesmith生成SQLSERVER实体(带注释)

记录用codesmith生成SQLSERVER数据库实体的一个模板,具体链接数据库和使用方式,大家可以百度,有非常多的资料,只记录一个模板:<%@ CodeTemplate Language=”C#” TargetLanguage=”C#” Debug=”False” Description=”Create a list of properties from database table.” %><%–声明数据库表的参数,在左下角的表属性中,选择要操作的数据库表–…

       记录用codesmith生成SQLSERVER数据库实体的一个模板,具体链接数据库和使用方式,大家可以百度,有非常多的资料,只记录一个模板:

 <%@ CodeTemplate Language="C#" TargetLanguage="C#" Debug="False" Description="Create a list of properties from database table." %> <%--声明数据库表的参数,在左下角的表属性中,选择要操作的数据库表--%> <%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context" Description="Table that the object is based on." %> <%--引入system类型转为c#的数据类型的映射字典 --%> <%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %> <%--引入下面的类库,操作数据库必备的。--%> <%@ Assembly Name="SchemaExplorer" %> <%@ Import Namespace="SchemaExplorer" %> using Dapper; using NLog; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Web;  namespace test {     //<%= SourceTable.Description %>     public class <%= SourceTable.Name %>     {         #region 数据库字段     <%--遍历数据库表的字段属性--%>     <% foreach (ColumnSchema column in this.SourceTable.Columns) {  %>     <%--拼接字符串,输出c#中实体的属性--%>         /// <summary>         ///<%= column.Description %>         /// </summary>         public <%= ControlType(CSharpAlias[column.SystemType.FullName]) %> <%= column.Name %>{ get; set; }          <% } %>         #endregion          #region 方法                  #endregion     } } <script runat="template">  //如果类型为int,或datetime类型输出可空类型  public string ControlType(object val)  {      var ty=val.ToString();      if(ty=="int")      {          return "int";      }      if(ty=="System.DateTime")      {          return "DateTime";      }      return ty;  } </script>

       涉及到表注释和字段注释,效果如下:

codesmith生成SQLSERVER实体(带注释)

数据库技术:codesmith生成SQLSERVER实体(带注释)地址:https://blog.csdn.net/sinat_28984567/article/details/107141873

需要了解更多数据库技术:codesmith生成SQLSERVER实体(带注释),都可以关注数据库技术分享栏目—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/dtteaching/629344.html

(0)
上一篇 2021年5月30日
下一篇 2021年5月30日

精彩推荐