Entity Framework generated classes are not in the namespace I require, is there a way of changing the namespace it uses without regenerating?

asp.net-mvc-4 entity-framework namespaces visual-studio

Question

Where should the namespace be provided if a regenerate is required? I am trying to use partial classes from within the Models namespace however they don't match.

The produced entity foundation classes are located in the condensed code segment below.

namespace projectname
{
   #region Contexts

   /// <summary>
  /// No Metadata Documentation available.
  /// </summary>
  public partial class MyClass
  {

  }
}

A class is added to my models folder,

namespace projectname.Models
{

    public partial class MyClass
    {
     //etc, etc 
    }
}

The compiler is seeing both project names, thus as you can see, the namespaces don't match, which causes problems when I try to utilize them. Models. project name and my class. MyClass.

I would like some advice on the correct way to fix this, preferably to update the E.F. classes so they exist in the projectname.Models namespace, but I am not sure how to go about it.

1
16
3/26/2015 1:23:41 PM

Accepted Answer

According to IIRC, you should be able to alter the namespace directly through the xml file or files if you are utilizing an Entity data model (you may have to change it for all the various storage and and conceptual models). It could even be possible to alter it in the designer—it sounds rather straightforward.

In fact, this could be the answer:

Overview of Generated Code (Entity Data Model Designer) (see Custom Tool Namespace)

6
12/28/2012 4:47:45 AM

Popular Answer

According to Roman O's comment, the "Custom Tool Namespace" property of the text transform (.tt) file, which links the entity model (.edmx) file and the generated entity classes (in the database first approach), can be updated to modify the namespace. With EF 5.0 and VS 2012 Express, this works.

I would post a screenshot, but my reputation would prevent me.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow