第一步:将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. 动态选路、RIP协议&&OSPF协议详解

    动态选路.RIP协议&&OSPF协议详解 概念 当相邻路由器之间进行通信,以告知对方每个路由器当前所连接的网络,这时就出现了动态选路.路由器之间必须采用选路协议进行通信,这样的选路协议 ...

  2. Java 8相关

    语言生态系统中的所有语言都有优胜劣汰的压力.虽然Java语言当前还在健康发展,但是保不定哪天就完蛋了. Java8增加的新特性从根本上来说是为了提高搬砖的姿势和效率. 多核编程的更好支持. 方法成为一 ...

  3. java导出word(带图片)

    public class CreateWordDemo { public void createDocContext(String file) throws DocumentException,IOE ...

  4. C#写入和读出文本文件

    C#写入和读出文本文件 写入文本文件 class WriteTextFile { static void Main() { //如果文件不存在,则创建:存在则覆盖 //该方法写入字符数组换行显示 st ...

  5. 【面试】http协议知识

    一.什么是HTTP协议        HTTP协议是一种应用层协议,HTTP是HyperText Transfer Protocol(超文本传输协议)的英文缩写.HTTP可以通过传输层的TCP协议在客 ...

  6. PKUSC2016

    day x(x<0) 外出培训倒数第二天晚上发烧了....逃过了第二天早上的考试,orz 抢到rank 1 的commonc神犇!! day 0 下午到了北大,发了两张50元饭卡.这是第三次来北 ...

  7. WPF 四种样式

    1.内联样式<TextBlock FontSize="20" Foreground="Blue">好啊</TextBlock> 2.页面 ...

  8. jQuery 使得文本框获得焦点

      今天遇见这么一个小小的问题,就是文本框中需要输入内容才可以提交,如果没有输入就提示并使该文本框获得焦点! 这么一个简单的事情如果没有使用jQuery的话 是不是对象.focus()就可以了, 可是 ...

  9. Mysql 5.7 使用SSL安全连接

    MySQL默认的数据通道是不加密的,在一些安全性要求特别高的场景下,我们需要配置MySQL端口为SSL,使得数据通道加密处理,避免敏感信息泄漏和被篡改.当然,启用MySQL SSL之后,由于每个数据包 ...

  10. redis使用watch完成秒杀抢购功能

    Redis使用watch完成秒杀抢购功能: 使用redis中两个key完成秒杀抢购功能,mywatchkey用于存储抢购数量和mywatchlist用户存储抢购列表. 它的优点如下: 1. 首先选用内 ...