第一步:将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. Hotaru's problem(hdu 5371)

    题意:给出一个数字串,询问最长的子串,满足以下要求:将子串平均分为三部分,一三部分相等,一二部分对衬. /* 在manachar的基础上,枚举回文串的中心,再找第三部分. */ #include< ...

  2. 继承的小DEMO

    代码如下 Student.java package four.com; public class Student extends Person { // private String name; // ...

  3. unity3d中串口的使用

    工作中遇到了串口的问题,通过查资料&实验写出了下面代码: 关于串口的代码我在网上看了好多,一种是用事件来做,另外一种使用线程来做:(经过试验,unity无法用串口自带的事件进行数据读取): 看 ...

  4. Oracle监听的静态注册和动态注册

    静态注册:通过解析listene.ora文件 动态注册:由PMON进程动态注册至监听中 在没有listener.ora配置文件的情况下,如果启动监听,则监听为动态注册.用图形化netca创建的监听,默 ...

  5. Win10 UWP vs add github

    vs github 插件 教程 官方教程 点击查看存储库,跳转到 DemoHttp for github

  6. python处理地理数据-geopandas和pyshp

    这边博客并不是有关geopandas的教程和pyshp的教程! 使用python来处理地理数据有很多相关的包,最近研究需要处理一些地理数据,然而arcgis的arcpy总是不能令人满意.所以这里说说p ...

  7. Microchip微芯HCS301解密HCS360解密HCS361芯片解密多少钱?

    Microchip微芯HCS系列芯片解密型号: HCS101 | HCS200 | HCS201 | HCS201T | HCS300 | HCS300T HCS301 | HCS301T | HCS ...

  8. 读取EXCEL数据到内存DataTable

    protected void Page_Load(object sender, EventArgs e) { string filepath = Server.MapPath("~/file ...

  9. js实现去重字符串

    实现去重字符串主要是把重复的字符与原来的字符(先push()进入一个数组存起来)相匹配,如果match返回的不是null则说明重复,就删除掉: <script> var str = pro ...

  10. [poj2337]求字典序最小欧拉回路

    注意:找出一条欧拉回路,与判定这个图能不能一笔联通...是不同的概念 c++奇怪的编译规则...生不如死啊... string怎么用啊...cincout来救? 可以直接.length()我也是长见识 ...