问题描述
我一直在尝试弄清楚如何使EF Power Tools-反向工程师代码首先 为生成的上下文文件使用不同的名称 ,
示例
我有一个名为 My_Awesome_Dev_Database的数据库。当我对它运行逆向工程时,生成的文件将被称为:
要执行的操作是指定要调用的文件,例如:
到目前为止的尝试
我尝试浏览EF.Utilities.CS.ttinclude文件,以了解文件名是如何生成的-但到目前为止,我一直没有成功。
有人知道吗?
提前感谢!
当前生成的上下文文件命名约定是硬编码的且不可配置。
所有逻辑都在 ReverseEngineerCodeFirstHandler $ c内部$ c>类(,或者-由于Entity Framework是开源的-请获取代码,添加此配置选项,然后发送回拉请求。
I have been attempting to figure out how to make the EF Power Tools - Reverse Engineer Code First use a different name for the generated Context-file, than what it uses now.
Example
I have a database called My_Awesome_Dev_Database. When I run Reverse-engineer against that, the file that is generated will be called:
What it would like to do is specify what the file is to be called, for instance:
Attempts so far
I have tried looking through the EF.Utilities.CS.ttinclude file, to figure out how the filename is generated - but I have been unsuccessful so far.
Does anyone know ?
Thanks in advance!
Currently the generated context file naming convention is hard-coded and non configurable.
All the logic is inside the ReverseEngineerCodeFirstHandler
class (the source is on CodePlex).
It sets the context file name and path with
var contextFilePath = Path.Combine(modelsDirectory,
modelGenerator.EntityContainer.Name + contextHost.FileExtension);
var contextItem = project.AddNewFile(contextFilePath, contextContents);
So the file name is coming from modelGenerator.EntityContainer.Name
which gets created upper in the method with:
var contextName =
connection.Database.Replace(" ", string.Empty)
.Replace(".", string.Empty) + "Context";
var modelGenerator =
new EntityModelSchemaGenerator(storeGenerator.EntityContainer,
"DefaultNamespace", contextName);
So as you can see the tool just takes the db name removes the spaces and dots and use it as the context name which will end up as the generated file name.
You can open an issue or - because Entity Framework is open source - take the code, add this configuration option, and send back a pull request.
这篇关于首先使用EF PowerTools反向工程师代码更改生成的上下文文件的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!