我怎样才能修改EDMX默认代码生成策略? [英] How can I modify the default code generation strategy for edmx?

查看:909
本文介绍了我怎样才能修改EDMX默认代码生成策略?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想修改默认的代码生成策略,我该怎么办呢?

I want to modify the default code generation strategy, how can I do that?

我只是想从<修改类名;#= code.Escape(集装箱)#> 实体和更改默认的连接字符串名称=默认

I simply want to modify the class name from <#=code.Escape(container)#> to Entities and change the default connection string to name=Default.

(我不想为项目创建一个模板文件,我想编辑它,所以它会在全球开展工作)

(I don't want to create a template file for the project, I want to edit it so it will work globally)

我搜索过 .TT 文件,我只能找到的ItemTemplate。我不知道什么是默认生成的代码,这是一个我想编辑

I've searched for .tt files, I could only find the ItemTemplates. I don't know what generates the code by default, this is the one I want to edit.

更新:我还是不知道如何做到这一点

Update: I still don't know how to do this.

推荐答案

您可以看到生成的代码,如果你点击你的EMDX文件,并在Visual Studio中查看文件的属性。查找自定义工具属性,会告诉你,EDMX XML转换成编译代码生成器的类名。

You can see what generates the code if you click your EMDX file and check file properties in Visual Studio. Look for Custom Tool property that will tell you the class name of the generator that converts EDMX XML into compilable code.

而对于模型定制,我还是建议你使用T4是把你的EDMX并生成相同的代码作为原始发生器。好事是,你就可以操纵它'如果你愿意,直到你去死吧!

But regarding model customization, I would still suggest you use T4 that takes your EDMX and generates the same code as original generator. The good thing is that you can then manipulate it 'till you drop dead if you will.

如果你打算使用几个EMDXs T4的项目中的话,我建议你,而创建一个 .ttinclude 文件,并在每个 .TT 文件中引用它。这样你会重用现有的代码,当你改变它,它会在所有生成的文件中反映出来。

And if you intend to use the T4 on several EMDXs in your project then I suggest you rather create a .ttinclude file and reference it in every .tt file. This way you will reuse existing code and when you'd change it it will be reflected on all generated files.

还有一个问题:什么你通过的全球的意思吗?在全球范围内为您的项目或为你的计算机上的所有文件EDMX或您的项目团队或什么都EDMX文件中的所有文件EDMX?定义的全球

One more question: What do you mean by globally? Globally for all EDMX files in your project or for all EDMX files on your machine or all EDMX files on your project team or what? Define globally.

既然你已经定义的 。全球的为特定的机器上这所有的项目是什么,我会怎么做。

Since you've defined global as all projects on a particular machine this is what I'd do.

首先:用T4允许您调整EDMX - >代码转换每个项目或每更好的解决方案,说变化(在一个特定的解决方案的所有项目)。在其他项目上/在同一台机器上的解决方案,你应该包括相同的T4模板引用。因此,这不是真正的全球的在你的感觉...

First of all: using T4 allows you to adjust EDMX -> code conversion changes per project or better said per solution (all projects in a particular solution). On other projects/solutions on the same machine, you should include the same T4 template reference. So it's not actually global in your sense...

你能做的最好的事情就是创建这个自定义的Visual Studio项模板T4模板,所以它一定会觉得很更容易增加这个默认的T4模板,您的解决方案/项目。 ,这是全球的,你可以通过T4使其

The best thing you could do is to create a custom Visual Studio item template with this T4 template so it'd be much much easier adding this default T4 template to your solutions/projects. That's as global as you can make it by T4.

也许你应该阅读谈论你的定制,这个MSDN项:结果
如何:自定义对象层代码生成(实体数据模型设计器)

Maybe you should read this MSDN entry that talks about your kind of customization:
How to: Customize Object-Layer Code Generation (Entity Data Model Designer)

这篇关于我怎样才能修改EDMX默认代码生成策略?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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