3
votes

I am using Entity Framework power tools to reverse engineer code from an existing database. I have more then one schema's in my database but i want to generate classes for dbo schema only. How i can customize it

2

2 Answers

4
votes

You must edit the Reverse Engineer Templates. I've done the following for Entity Framework 6.

On Context.tt the schema is currently unavailable so unwanted code will have to be deleted manually..

On Entity.tt and Mapping.tt you must change the code here.

var efHost = (EfTextTemplateHost)Host;
var code = new CodeGenerationTools(this);

to

var efHost = (EfTextTemplateHost)Host;
if((string)efHost.TableSet.MetadataProperties["Schema"].Value == "dbo"){
var code = new CodeGenerationTools(this);

And then place a closing bracket at the end of those two files.

<#
}
#>

Change "dbo" to whatever you desire.

1
votes

You can use the T4 templates (on Entity Framework menu > Customize Reverse Engenieer Templates). On those you can test the schema: if (efHost.TableSet.MetadataProperties["Schema"].Value == "Correct Schema") // generate