第一步:将PowerDesigner表字段的中文Name填入Comment中:工具-Execute Commands-Edit/Run Script...

'******************************************************************************
'* File: name2comment.vbs
'* Title: Name to Comment Conversion
'* Model: Physical Data Model
'* Objects: Table, Column, View
'* Author: steveguoshao
'* Created: 2013-11-29
'* Mod By:
'* Modified:
'* Version: 1.0
'* Memo: Modify from name2code.vbs
'****************************************************************************** Option Explicit
ValidationMode = True
InteractiveMode = im_Batch Dim mdl ' the current model ' get the current active model
Set mdl = ActiveModel
If (mdl Is Nothing) Then
MsgBox "There is no current Model "
ElseIf Not mdl.IsKindOf(PdPDM.cls_Model) Then
MsgBox "The current model is not an Physical Data model. "
Else
ProcessFolder mdl
End If ' This routine copy name into comment for each table, each column and each view
' of the current folder
Private sub ProcessFolder(folder)
Dim Tab 'running table
for each Tab in folder.tables
if not tab.isShortcut then
tab.comment = tab.name
Dim col ' running column
for each col in tab.columns
col.comment= col.name
next
end if
next Dim view 'running view
for each view in folder.Views
if not view.isShortcut then
view.comment = view.name
end if
next ' go into the sub-packages
Dim f ' running folder
For Each f In folder.Packages
if not f.IsShortcut then
ProcessFolder f
end if
Next
end sub

name2comment.vbs

(可保存为文件以后直接打开执行)

第二步:从PowerDesigner表字段的Comment到SQL Server表字段的MS_Description(说明):数据库-Generate Database...

第三步:创建EF edmx文件

第四步:将SQL Server表字段的MS_Description(说明)添加到EF edmx文件:

EFTSQLDocumentation.Generator.exe -c "Data Source=.;Initial Catalog=xxxdb;User ID=sa;Password=yyy;" -i "上一步生成的edmx文件的完整路径"

然后刷新edmx(从数据库更新模型),可以多刷两遍。

(EFTSQLDocumentation.Generator.exe可到https://eftsqldocgenerator.codeplex.com/下载)

最后一步:修改生成实体类的T4模板(默认叫Model1.tt):

Model1.tt Namespace段:

public void BeginNamespace(CodeGenerationTools code)
{
var codeNamespace = code.VsNamespaceSuggestion();
if (!String.IsNullOrEmpty(codeNamespace))
{
#>
namespace Models
{
using System.ComponentModel.DataAnnotations;
<#+
PushIndent(" ");
}
} public void EndNamespace(CodeGenerationTools code)
{
if (!String.IsNullOrEmpty(code.VsNamespaceSuggestion()))
{
PopIndent();
#>
}
<#+
}
}
    public string Property(EdmProperty edmProperty)
{
string doc = "";
if (edmProperty.Documentation != null)
{
doc = string.Format(
CultureInfo.InvariantCulture,
"\n\t\t/// <summary>\n\t\t/// {0} - {1}\n\t\t/// </summary>\n\t\t",
edmProperty.Documentation.Summary ?? "",
edmProperty.Documentation.LongDescription ?? ""); doc += string.Format(
CultureInfo.InvariantCulture,
"[Display(Name = \"{0}\")]\n\t\t",
edmProperty.Documentation.Summary.Replace('(', '_').Replace(')', '_').Replace('(', '_').Replace(')', '_').Replace(" ", "") ?? "",
edmProperty.Documentation.LongDescription ?? "");
} if (!edmProperty.Nullable)
{
doc += "[Required(ErrorMessage = \"您需要填写{0}!\")]\n\t\t";
} var maxLengthFacet = (Facet)edmProperty.TypeUsage.Facets.SingleOrDefault(f => f.Name == "MaxLength");
if(maxLengthFacet != null && !maxLengthFacet.IsUnbounded)
{
doc += "[StringLength("+ maxLengthFacet.Value +", ErrorMessage = \"{0}长度不能超过"+ maxLengthFacet.Value +"\")]\n\t\t";
} return doc + string.Format(
CultureInfo.InvariantCulture,
"{0} {1} {2} {{ {3}get; {4}set; }}",
Accessibility.ForProperty(edmProperty),
_typeMapper.GetTypeName(edmProperty.TypeUsage),
_code.Escape(edmProperty),
_code.SpaceAfter(Accessibility.ForGetter(edmProperty)),
_code.SpaceAfter(Accessibility.ForSetter(edmProperty)));
} public string NavigationProperty(NavigationProperty navigationProperty)
{
var endType = _typeMapper.GetTypeName(navigationProperty.ToEndMember.GetEntityType());
string doc = "";
if (navigationProperty.Documentation != null)
{
doc = string.Format(
CultureInfo.InvariantCulture,
"\n\t\t/// <summary>\n\t\t/// {0} - {1}\n\t\t/// </summary>\n\t\t",
navigationProperty.Documentation.Summary ?? "",
navigationProperty.Documentation.LongDescription ?? "");
} return doc + string.Format(
CultureInfo.InvariantCulture,
"{0} {1} {2} {{ {3}get; {4}set; }}",
AccessibilityAndVirtual(Accessibility.ForProperty(navigationProperty)),
navigationProperty.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many ? ("ICollection<" + endType + ">") : endType,
_code.Escape(navigationProperty),
_code.SpaceAfter(Accessibility.ForGetter(navigationProperty)),
_code.SpaceAfter(Accessibility.ForSetter(navigationProperty)));
}

Model1.tt Property段

效果:

//------------------------------------------------------------------------------
// <auto-generated>
// 此代码是根据模板生成的。
//
// 手动更改此文件可能会导致应用程序中发生异常行为。
// 如果重新生成代码,则将覆盖对此文件的手动更改。
// </auto-generated>
//------------------------------------------------------------------------------ namespace Models
{
using System.ComponentModel.DataAnnotations;
using System;
using System.Collections.Generic; public partial class Custom
{ /// <summary>
/// 客户ID -
/// </summary>
[Display(Name = "客户ID")]
[Required(ErrorMessage = "您需要填写{0}!")]
public int CustomID { get; set; } /// <summary>
/// 客户名称 -
/// </summary>
[Display(Name = "客户名称")]
[Required(ErrorMessage = "您需要填写{0}!")]
[StringLength(, ErrorMessage = "{0}长度不能超过60")]
public string CustomName { get; set; }

参考:

http://www.iteye.com/topic/1138201

http://www.cnblogs.com/hhhh2010/p/5344256.html

http://stackoverflow.com/questions/13931159/add-documentation-to-generated-code-in-entity-framework-model-first

https://eftsqldocgenerator.codeplex.com/

Entity Framework Power Tools:https://visualstudiogallery.msdn.microsoft.com/72a60b14-1581-4b9b-89f2-846072eff19d/

谢谢小伙伴wwl、jxt

从PowerDesigner表字段的Name到EF实体类属性的Display Name(根据PowerDesigner生成EF实体类中文注释和验证元数据)的更多相关文章

  1. pojo类对应的就是数据库中的表,pojo类属性类型一定要用包装类Integer等

    pojo类对应的就是数据库中的表,pojo类属性类型一定要用包装类Integer等 pojo类对应的就是数据库中的表,pojo类属性类型一定要用包装类Integer等 pojo类对应的就是数据库中的表 ...

  2. PowerDesigner表创建脚本双引号问题

    在使用PowerDesigner表属性的Preview查看创建脚本的时候,发现大多表名和字段名都加上了双引号,而且有引号的都是大小写混合的,导致创建的表里,表名和字段名也都是大小写混合的. 在一番搜索 ...

  3. 【转】PowerDesigner物理数据表生成C#实体类Model

    model实体类是什么: 在三层架构UI,BLL,DAL中,有时用户插入一条记录到数据库中,必然会有不少数据,按正常编程,也必然会一下子调用某个函数传入不少参数.为了减少参数的数量,达到高效简洁的效果 ...

  4. salesforce 零基础开发入门学习(四)多表关联下的SOQL以及表字段Data type详解

    建立好的数据表在数据库中查看有很多方式,本人目前采用以下两种方式查看数据表. 1.采用schema Builder查看表结构以及多表之间的关联关系,可以登录后点击setup在左侧搜索框输入schema ...

  5. EF Power Tools的Reverse Engineer Code First逆向生成Model时处理计算字段

    VS2013上使用EF Power Tools的Reverse Engineer Code First逆向生成Model时,没有处理计算字段.在保存实体时会出现错误. 可以通过修改Mapping.tt ...

  6. 知识备忘phpcms 简单解析一 数据表字段

    PHPCMS V9帮助中心 数据结构 phpcms v9 数据... phpcms v9 数据... PHPSSO 数据库结... phpcms v9 数据表结构 在线版 PHPCMS V9 数据结构 ...

  7. plsql修改表字段alter

    场景:在生产过程中有时候需要不同的环境中修改表字段,使用sql语句比较方便! 1 演示 --添加字段的语法 alter table tablename add (column datatype [de ...

  8. TSQL:A表字段与B表中的关联,关联条件中一列是随机关联的实现方式

    A表字段与B表中的关联,关联条件中一列是随机关联的实现方式 create table test( rsrp string, rsrq string, tkey string, distan strin ...

  9. mysql 动态拼接表字段,值 mybatis 动态获取表字段

    -- 取表所有字段,自动用逗号分开 select GROUP_CONCAT(DISTINCT COLUMN_NAME) from information_schema.columns where ta ...

随机推荐

  1. 站点SEO优化日记之设置目标关键词

    一.怎样确定关键词? 根据百度指数,选择搜索指数较高的作为候选关键词.一个关键词的搜索结果中,若大部分都为非首页链接,则该关键词可在短时间内通过优化获得好的排名,可选择此类关键词作为目标关键词. 二. ...

  2. <select> 默认选中

    不多bb,直接上代码 html代码: <li><span>所属类别</span> <select id="cate" name=" ...

  3. Logging vs NoLogging

    You Asked My Prod environments is like this. Three Node RAC, Active Data guard enabled. There is a p ...

  4. C# 五、谈扩展方法的理解

    http://www.cnblogs.com/zhaopei/p/5678842.html

  5. 如何使用XShell登录亚马逊EC2云服务器

    http://jingyan.baidu.com/article/a3a3f811d5fc338da2eb8a00.html

  6. Linux 下MySql 重置密码

    1.首先确认服务器出于安全的状态,也就是没有人能够任意地连接MySQL数据库. 因为在重新设置MySQL的root密码的期间,MySQL数据库完全出于没有密码保护的 状态下,其他的用户也可以任意地登录 ...

  7. CodeForces 548

    A. Mike and Fax time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  8. Java 集合系列04之 fail-fast总结(通过ArrayList来说明fail-fast的原理、解决办法)

    概要 前面,我们已经学习了ArrayList.接下来,我们以ArrayList为例,对Iterator的fail-fast机制进行了解.内容包括::1 fail-fast简介2 fail-fast示例 ...

  9. android 修改 SwitchPreferenceCompat 高度,内边距,字体大小

    public class FontSizeSwitchPreferenceCompat extends SwitchPreferenceCompat { private Context mContex ...

  10. GridView的七种数据绑定列的类型

    1.BoundField 用于显示普通文本,是默认的数据绑定列的类型,一般自动生成的列就是该类型,需要注意是DataFormatString属性,该属性可以设置显示的格式,常见格式有:{0:C} 设置 ...