zoukankan      html  css  js  c++  java
  • EF6 根据数据库字段说明,生成字段注释

    第一步: 在Model.tt文件添加一个方法读取数据库中的字段说明

      找到public string Property(EdmProperty edmProperty)这个方法,添加到这个方法下面

    public string GetRemark(EdmProperty edmProperty){  
            //System.Diagnostics.Debugger.Launch();  
            var tableName = edmProperty.DeclaringType.Name;  
            var colName=_code.Escape(edmProperty);  
            //System.Diagnostics.Debugger.Break();  
            string sql = string.Format(@"SELECT  字段说明=isnull(props.[value],'')  FROM syscolumns cols  inner join sysobjects objs on cols.id= objs.id and  objs.xtype='U' and  objs.name<>'dtproperties'  left join sys.extended_properties props on cols.id=props.major_id and cols.colid=props.minor_id  where  objs.name='{0}' and cols.name='{1}'",tableName,colName);  
            string sqlcon = "Data Source=191.108.12.130;User ID=sa;Password=123456;Initial Catalog=TTTT";  
            object remark=new object();  
            using(System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(sqlcon)){  
                conn.Open();  
                System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(sql, conn);  
                remark =cmd.ExecuteScalar();      
            }        

     第二步:找到var simpleProperties = typeMapper.GetSimpleProperties(entity);修改如下:

    var simpleProperties = typeMapper.GetSimpleProperties(entity);
        if (simpleProperties.Any())
        {
            foreach (var edmProperty in simpleProperties)
            {
            #>  
        /// <summary>  
        /// <#=codeStringGenerator.GetRemark(edmProperty)#>  
        /// </summary>  
        <#=codeStringGenerator.Property(edmProperty)#>  
    <# 
            }
        }

    第三步:保存模板,就可以看到实体字段注释

  • 相关阅读:
    Android框架: MVC MVP MVVM
    Apache Tomcat -8.0.45
    【MySQL】Database connections will be migrated
    MySQL(mysql-installer-community-5.7.18.1 Windows10)
    代码版本控制(Source Control)
    HTML 5
    微信小程序
    Android Studio 2.3.3 安装
    React Native
    2018面向对象程序设计(Java)第12周学习指导及要求
  • 原文地址:https://www.cnblogs.com/kcjm/p/7676904.html
Copyright © 2011-2022 走看看