Dovydas Navickas
Dovydas Navickas

Reputation: 3591

Is it possible to set .edmx models output directory to other project in solution?

I need to have my .edmx file in my Data project and its generated models in my Data.Model project. Is it possible? And if so, how?

Upvotes: 0

Views: 1621

Answers (1)

James Blackwell
James Blackwell

Reputation: 56

Are you using the EF DbContext Generator to generate code-first models? If so, you can build your .edmx file the same way you always do. Once it is created and the models are generated, move the MyContext.tt template into your Data.Models project (Leave your MyContext.Context.tt file in the project with your .edmx).

After that, open up the Context.tt and near the top change the inputFile to the relative path of your Data.Model project. It will end up something like:

string inputFile = @"../MyProject.Data.Model/MyDataModel.edmx";

Go back to your MyContext.Context.tt in your .Data project and change the CustomToolNamespace property to Data.Model

From then on, when you make changes to your .edmx file, you will have to also go into your Data.Model project and save the MyContext.tt again to regenerate the models.

Upvotes: 4

Related Questions