获取 T4 模板中 edmx 的命名空间
当我将模板安装到与 edmx 命名空间不同的命名空间中时,生成的代码由于缺少命名空间而出现错误。
所以我试图添加一个“using”语句来解决这个问题,但我不知道如何获取 edmx 所在的命名空间。
到目前为止我已经做到了(为简洁起见进行了编辑):
<#@ template debug="true" hostspecific="true" language="C#" #>
<#@ include file="EF.Utility.CS.ttinclude"#>
<#@ output extension=".cs"#>
const string edmxFile = @"../Entities/NorthwindEntities.edmx";
CodeGenerationTools code = new CodeGenerationTools(this);
string namespaceName = code.VsNamespaceSuggestion();
string edmxNamespaceName = "???";
using System;
using System.Data.Objects;
using System.Data.Objects.DataClasses;
using <#= edmxNamespaceName #>;
namespace <#= namespaceName #>
{
// ...
}
请帮我解决“ edmx命名空间名称”。
谢谢!
When I install my template into a different namespace than the edmx's namespace the code that is generated has errors because of the missing namespace.
So I'm trying to add a "using" statement to solve this problem, but I don't know how to get the namespace the edmx is in.
I have this so far (edited for brevity):
<#@ template debug="true" hostspecific="true" language="C#" #>
<#@ include file="EF.Utility.CS.ttinclude"#>
<#@ output extension=".cs"#>
const string edmxFile = @"../Entities/NorthwindEntities.edmx";
CodeGenerationTools code = new CodeGenerationTools(this);
string namespaceName = code.VsNamespaceSuggestion();
string edmxNamespaceName = "???";
using System;
using System.Data.Objects;
using System.Data.Objects.DataClasses;
using <#= edmxNamespaceName #>;
namespace <#= namespaceName #>
{
// ...
}
please help me solve for "edmxNamespaceName".
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 MetadataLoader 类
You can use the MetadataLoader class
这是旧的,但由于我偶然发现它寻找答案,我将提供我发现的内容...... *.tt 的属性包括一个名为“自定义工具命名空间”的选项。这将覆盖 MetadataLoader 的使用,MetadataLoader 查看物理结构以确定命名空间。我必须为我的旧数据库第一个项目的 .Context.tt 和 .tt 文件设置此项。
感谢这里的回复,让我走上了正确的道路。
This is old, but since I stumbled upon it looking for an answer, I'll provide what I found... the properties of the *.tt includes an option called "Custom Tool Namespace". This will override the use of the MetadataLoader which looks at the phyical structure to determine the namespace. I had to set this for both the .Context.tt and .tt files for my old database first project.
Credit to this responses here that put me on the right path.