【发布时间】:2013-10-10 22:01:12
【问题描述】:
其实我需要的应该很简单。
我想用它们各自的类名对所有生成的类添加一个 XML 注释。
目前,生成的类如下所示:
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace MyProject.Models
{
using System;
using System.Collections.Generic;
public partial class Foo {
...
}
}
我们的 T4 模板名为 WebEntities.tt,包含在名为 WebEntities.edmx 的实体数据模型中。
修改 WebEntities.tt 并执行“运行自定义工具”后,我希望得到以下结果:
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace MyProject.Models
{
using System;
using System.Collections.Generic;
/// <summary>
/// My comments for Foo
/// </summary>
public partial class Foo {
...
}
}
但我的问题是看看,在哪里以及如何我可以在模板中添加此更改。
T4 模板是通过创建新的 .edmx 文件生成的。
我看过一些教程,但没有进一步解释这种 T4 模板。
有什么想法吗?
亲切的问候
更新:
我在这篇文章中添加了更多信息并正确更改了标题。
之前,我认为“webEntities.tt”这个名称和“web.config”一样常见,但这是错误的。
【问题讨论】:
-
这个 WebEntities.tt 是什么?它在互联网上的某个地方可用吗?你能概括一下吗?
-
它是一个文本模板,用于生成映射到数据库模型的所有类。我们有一个名为“WebEntities.edmx”的 .edmx 文件。它包括名为“WebEntities.tt”的文件,并通过创建 .edmx 文件生成
标签: c# entity-framework-5 t4