4

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:

My_Awesome_Dev_DatabaseContext.cs

What it would like to do is specify what the file is to be called, for instance:

MyAwesomeDatabaseContext.cs

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!

1 Answers1

5

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.

nemesv
  • 138,284
  • 16
  • 416
  • 359
  • Although it doesn't solve the problem, I think it's as close as we are going to get to an answer. We have found several ways to solve the problem -- and ofcourse the best solution would be to create the pull-request. Will look into that. Thanks for the help. –  Oct 15 '13 at 07:17