在T4模板中获取edmx的名称空间 [英] Getting the namespace for an edmx in a T4 template

查看:117
本文介绍了在T4模板中获取edmx的名称空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将模板安装到与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.

因此,我试图添加一个 using语句来解决此问题,但是我不知道如何获取edmx所在的名称空间。

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 #>
{
    // ...
}

请帮助我解决了 edmxNamespaceName。

please help me solve for "edmxNamespaceName".

谢谢!

推荐答案

此是旧的,但是由于偶然发现它寻找答案,因此我将提供所发现的内容。* .tt的属性包括一个名为自定义工具命名空间的选项。这将覆盖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.

这篇关于在T4模板中获取edmx的名称空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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