实体框架电动工具逆向工程师代码首先进入一个文件夹 [英] Entity Framework Power Tools Reverse Engineer Code First into a folder

查看:115
本文介绍了实体框架电动工具逆向工程师代码首先进入一个文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用实体框架电力工具逆向工程师代码首先从数据库生成我的POCO类,映射文件和上下文。我能够根据我的数据库模式更改T4模板以生成不同的命名空间,但是我无法找到如何根据表模式创建一个文件夹,并将相关的POCO类放在文件夹中。



有人可以帮忙吗?
谢谢

解决方案

更新



如其他答案所述,这种方法将无法正常工作。所以答案不再适用。



您可以尝试通过执行以下操作来解决输出路径并创建一个文件夹:

 <#@ import namespace =System.IO#> 

var efHost =(EfTextTemplateHost)主机;
var outputPath = Path.Combine(Path.GetDirectoryName(efHost.TemplateFile),YourFolder);

if(!Directory.Exists(outputPath))
Directory.CreateDirectory(outputPath);

现在可以输出到不同的文件夹,您可以尝试使用类似于的生成环境这个:

 <#@ dte processor =T4Toolbox.DteProcessor#> 
<#@ TransformationContext processor =T4Toolbox.TransformationContextProcessor#>
<#@ assembly name =System.Xml#>
<#@ assembly name =EnvDTE#>
<#@ import namespace =T4Toolbox#>

ProcessOutputTemplate template = new ProcessOutputTemplate(this.GenerationEnvironment.ToString());
template.Output.File = outputPath;
template.Render();
this.GenerationEnvironment.Clear();

注意:这种方法需要在VS 2012/13中安装T4 Toolbox - http://www.olegsych.com/t4toolbox/ http://www.olegsych.com/t4toolbox/gettingstarted/


I'm using Entity Framework Power Tools Reverse Engineer Code First to generate my POCO classes, mapping files, and context from the database. I was able to change the T4 templates to generate a different namespace based on my database schema, but I am not able to find how to create a folder based on the tables schema and place the related POCO classes in the folder.

Could somebody help? Thanks

解决方案

Update

As mentioned in other answer this approach won't work. So the answer is no longer applied.

You can try resolving the output path and create a folder by doing the following:

<#@ import namespace="System.IO" #>

var efHost = (EfTextTemplateHost)Host;
var outputPath = Path.Combine(Path.GetDirectoryName(efHost.TemplateFile), "YourFolder");

if (!Directory.Exists(outputPath))         
  Directory.CreateDirectory(outputPath);

Now to output to different folder you can try using the GenerationEnvironment similar to this:

<#@ dte processor="T4Toolbox.DteProcessor" #>
<#@ TransformationContext processor="T4Toolbox.TransformationContextProcessor" #>
<#@ assembly name="System.Xml" #>
<#@ assembly name="EnvDTE" #>
<#@ import namespace="T4Toolbox" #>

ProcessOutputTemplate template = new ProcessOutputTemplate(this.GenerationEnvironment.ToString());
template.Output.File = outputPath;
template.Render();
this.GenerationEnvironment.Clear();

Note: this approach requires the T4 Toolbox installed in the VS 2012/13 - http://www.olegsych.com/t4toolbox/ (http://www.olegsych.com/t4toolbox/gettingstarted/)

这篇关于实体框架电动工具逆向工程师代码首先进入一个文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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