更改EF Power Tools Beta 3中生成的文件名 [英] Change the generated file name in EF Power Tools Beta 3

查看:87
本文介绍了更改EF Power Tools Beta 3中生成的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索过,但无法找到这个问题的答案。目前我们的Db用户前缀为表 - 例如向tblUsers。我更新了EF模板,以从生成的类名中删除tbl。但是我仍然无法弄清楚如何更改输出文件名来匹配。

I've searched but haven't been able to find an answer to this question. Currently our Db users prefixes of tables - e.g. tblUsers. I've updated the EF templates to remove the "tbl" from the generated class names. However I still can't figure out how to change the output file name to match.

是可能还是要求月亮?我在VS 2012中使用EF Power Tools Beta 3。任何帮助将非常感激!

Is it possible or am I asking for the moon? I’m using EF Power Tools Beta 3 in VS 2012. Any help would be GREATLY appreciated!

推荐答案

Patrick,你需要什么是修改EF电动工具使用的T4模板。当您要使用所有映射创建代码,而不是反向工程师代码优先选项,请选择自定义反向工程师模板。你应该得到三个文件:

Patrick, what you need is to modify the T4 template used by the EF Power Tools. When you want to create a code-first with all the mappings, instead of Reverse Engineer Code First option, choose Customize Reverse Engineer Template. You should get three files:


  1. Context.tt

  2. Entity.tt

  3. Mapping.tt

例如,在Mapping.tt中有一行从TableSet读取MetadataProperties,并提取表名称。该行如下所示:

For example, in Mapping.tt there is a line that reads MetadataProperties from a TableSet, and which extracts Table name. The line looks like this:

var tableSet = efHost.TableSet;
var tableName = (string)tableSet.MetadataProperties["Table"].Value ?? tableSet.Name;

这是您需要进行更改的地方,请执行以下操作:

This is where you need to make changes and do something like:

var newTableName = tableName.Replace("tbl", String.Empty);

当然,您应该选择不同的策略,并使用 Substring 方法或正则表达式读取和删除前三个字符。之后,您必须通过 tt 文件,并使用您的逻辑来使用 tableName 以及用户 newTableName 变量。您将使用数据库中的表将tableName保留在其中,并在其中要使用该名称作为POCO类和文件名的newTableName。

Of course, you should opt for a different strategy and use Substring method or Regular expression to read and remove the first three characters. After that you have to go through the tt file and use your logic where you want to use tableName and where to user newTableName variable. You will keep tableName where the mapping is done with the table in a database, and newTableName where you want to use that name for your POCO classes and filenames.

重复此过程为其他两个文件。有关更多信息,请参阅Rowan Miller的博客文章。这应该给你一个很好的主意如何继续。

Repeat the process for the other two files. For more information have a look at Rowan Miller's blog article. This should give you a pretty good idea how to proceed.

这篇关于更改EF Power Tools Beta 3中生成的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆