none
EF4: How to change/define the c# namespace of the generated code in .Designer file? RRS feed

Answers

  • Hi again,

     

    JAReyes’s post is very helpful if you are using some T4 template to generate the entity classes source codes.  However, if you are using EF auto-generated tool (EntityModelCodeGenerator) to generate the entity class, we can set the source code (.Designer.cs) namespace as:

     

    Left click the .edmx file to open the .edmx File Properties window à Modify the value of “Custom Tool Namespace”.  à Then the .Designer.cs file namespace will be modified. 

     

    Note that, by default “Custom Tool Namespace” property will be empty, so the Designer.cs file’s namespace is the project default namespace. 

     

    If you have any questions, please feel free to let me know.

     

    Good day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Max_2010 Thursday, October 7, 2010 3:09 PM
    Tuesday, October 5, 2010 3:40 AM
    Moderator

All replies

  • Hi,

    You must open your EDMX model, right-click on it, select Properties option and change the Namespace value.

    Hope this can help you,

    JAReyes.


    Please remember to Vote & "Mark As Answer" if this post is helpful to you.
    Por favor, recuerda Votar y "Marcar como respuesta" si la solucion de esta pregunta te ha sido útil.
    Wednesday, September 29, 2010 7:32 AM
  • I have tried that. I thing the namesapce you are talking about is for something else (not sure what exactly it is!). When you chnage that namespace, it changes the EdmEntityTypeAttribute.

     

     

    Wednesday, September 29, 2010 1:36 PM
  • Well,

    In this case, the namespace is created and overwrited automatically in the Designer by the default T4 generation template.

    If you use STE or POCO entities, you could specify your own T4 template and set there the namespace you want to use.

    To perform this, you must right-click the model and select "Add Code Generation Item...". Then you must select the type of template you prefer.

    Then, you can oper your Model.tt file (nor Model.*.tt file) and change this code line:

    namespace <#=code.EscapeNamespace(namespaceName)#>

    And replace this for your own namespace:

    namespace Here.Goes.MyOwn.Namespace

    Hope this can help you,

    JAReyes.


    Please remember to Vote & "Mark As Answer" if this post is helpful to you.
    Por favor, recuerda Votar y "Marcar como respuesta" si la solucion de esta pregunta te ha sido útil.
    Wednesday, September 29, 2010 2:00 PM
  • I have tried that. I thing the namesapce you are talking about is for something else (not sure what exactly it is!). When you chnage that namespace, it changes the EdmEntityTypeAttribute.

    Hello,

    If you mean the generated file by default when adding an EF data model (by default the namespace is your project name). Please try to modify it manully. By default, we do not recommend modify the auto-generated files, modifying it may cause unexpected behavior.

    Best regards


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback, please tell us.
    Welcome to the All-In-One Code Framework!
    Friday, October 1, 2010 4:31 AM
  • Hi Roahn,

    Of course manually changing the .Designer.cs file doesn’t solve the issues as it always overridden by the code generator.

    Are you suggesting that there is no out of the box feature that allows developers to change the C# namespace of the generated code in the .Designer file?

    Does this mean that the Namespace of the context and all of entities has to stay the same as the project’s default namespace?

    What is the “Namespace” property of the entity model when we open it in the edmx ide designer?

    Thanks for help.

    Tuesday, October 5, 2010 1:40 AM
  • Hi again,

     

    JAReyes’s post is very helpful if you are using some T4 template to generate the entity classes source codes.  However, if you are using EF auto-generated tool (EntityModelCodeGenerator) to generate the entity class, we can set the source code (.Designer.cs) namespace as:

     

    Left click the .edmx file to open the .edmx File Properties window à Modify the value of “Custom Tool Namespace”.  à Then the .Designer.cs file namespace will be modified. 

     

    Note that, by default “Custom Tool Namespace” property will be empty, so the Designer.cs file’s namespace is the project default namespace. 

     

    If you have any questions, please feel free to let me know.

     

    Good day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Max_2010 Thursday, October 7, 2010 3:09 PM
    Tuesday, October 5, 2010 3:40 AM
    Moderator