45

I am trying to change the Namespace used by Entity Framework Generator of classes.

When I click the designer of my Entity, Model.edmx, I can see somewhere where I can change the namespace:

Namespace

under ConceptualEntityModel properties. Changed that namespace, but nothing happened. Didn't work. So, I read some help from this link:

http://weblogs.asp.net/zeeshanhirani/struggling-through-namespace-in-entity-framework

says that I have to change the property: Custom Tool Namespace

That's nice, when I click property of .edmx in console application, there property is there. But when I am using the same thing in a Web Application, the property is not there. There is only a property file called Web File Properties that simply has 3 properties:

  • Custom Tool
  • File Name
  • Full Path

What am I missing here?

TatiOverflow
  • 1,071
  • 2
  • 16
  • 23

4 Answers4

70

rainerh is right:

I tried to set *.edmx Custom Tool Namespace property - this did not help.
I tried to set *.Context.tt property - this did not help too.
But when I set Custom Tool Namespace property of *.tt file (right-click on the file -> Properties) - namespace was set automatically for all the classes genereated before.

Hakan Fıstık
  • 16,800
  • 14
  • 110
  • 131
Taras Kozubski
  • 1,854
  • 1
  • 20
  • 33
  • 2
    The only thing it didn't change was the *.Context.cs file reference ... to change this you need to set the default namespace on your project properties. – dodgy_coder Apr 01 '16 at 00:32
  • 3
    For this to work properly, I had to set the Custom Tool Namespace property on the *.Context.tt and the *.tt files. – JasonH Sep 01 '16 at 13:53
  • Just a tip: The "show all files" option in the solution explorer should be enabled to expand the edmx model – rasputino Sep 13 '19 at 11:51
5

Open your edmx file first then press F4 or click on the properties window. Under the Schema section, there is a property called Namespace which you can modify.

Scotty
  • 1,127
  • 1
  • 7
  • 17
  • 4
    Ok, try this... in your solution explorer, expand out your edmx to see .Context.tt. Right click on the Context.tt file and select Properties. The Custom Tool Namespace property is in there. Try updating that and see what happens – Scotty Nov 13 '14 at 00:31
  • 1
    In my case it was not the .Context.tt but only the .tt I am using Entity Framework in version 6.1.3 – rainerhahnekamp Aug 27 '15 at 13:31
  • 1
    thanks. I wanted to change the `model namespace` i.e., the name of the generated `DbContext` class and this was exactly what I needed. – user1593842 Sep 25 '19 at 13:39
  • 1
    WOW! This worked!!! This should be the accepted answer! – Sam Jun 15 '21 at 08:47
4

In my case, I just simply created a folder within the project, moved the .edmx file to the folder I created(using the solution explorer), and everything just automatically changed namespaces.

Ray Lionfang
  • 689
  • 6
  • 17
0

My issue was that I had to rename a solution and the default namespace and assembly name hadn't gotten changed to the new name. After making sure your namespace is correct in the EDMX designer, right click on your project to open properties and update the default namespace and assembly name and we were good.

George Fabish
  • 409
  • 2
  • 14