Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

If I need to regenerate where should the namespace be specified. I am trying to use partial classes from within the Models namespace however they don't match.

The simplified code fragment below is where the entity framework classes have been generated

namespace projectname
{
   #region Contexts

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

  }
}

When I add a class to my models folder,

namespace projectname.Models
{

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

As you can see the namespaces don't match causing issues when I try and use them as the compiler is seeing both projectname.Models.MyClass and projectname.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.

like image 534
John Fleming Avatar asked Dec 28 '12 03:12

John Fleming


1 Answers

In line with Roman O's comment, namespace can be changed by updating "Custom Tool Namespace" property of text transform (.tt) file, which ties generated entity classes (in Database First approach) to entity model (.edmx) file. This works in VS 2012 Express with EF 5.0.

I would post a screenshot but for lack of reputation.

like image 103
sivraj Avatar answered Sep 30 '22 01:09

sivraj