首页 > 编程 > C# > 正文

c#中xml文档注释编译dll引用到其它项目示例

2020-01-24 02:48:52
字体:
来源:转载
供稿:网友

复制代码 代码如下:

<#@ template debug="True" hostspecific="True" language="C#" #><#@ assembly name="System.Core" #>
<#@ assembly name="System.Data" #>
<#@ assembly name="System.xml" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.Data" #>
<#@ import namespace="System.Data.SqlClient" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ output extension=".cs" #>

using System;
using DotNet.Framework.DataAccess.Attribute;
using System.Data;
namespace MyProject.Entities
{   
<#
    string connectionString = "Data Source=localhost;Initial Catalog=EDNFramework;User ID=sa;pwd=as";
    SqlConnection conn = new SqlConnection(connectionString);
    conn.Open();
    System.Data.DataTable schema = conn.GetSchema("TABLES");
    string selectQuery = "select * from @tableName";
    SqlCommand command = new SqlCommand(selectQuery,conn);
    SqlDataAdapter ad = new SqlDataAdapter(command);
    System.Data.DataSet ds = new DataSet();
    foreach(System.Data.DataRow row in schema.Rows)
    {
#>

    public class <#= row["TABLE_NAME"].ToString()#>
    {<#
        ds.Tables.Clear();
        command.CommandText = selectQuery.Replace("@tableName",row["TABLE_NAME"].ToString());
        ad.FillSchema(ds, SchemaType.Mapped, row["TABLE_NAME"].ToString());
        foreach (DataColumn dc in ds.Tables[0].Columns)
        {#>

        [DataMapping("<#= dc.ColumnName #>")]
        public <#= dc.DataType.Name #> <#= dc.ColumnName #> { get; set; }
       <#}#>       
    }           
    <#}#>              
}

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表