is there a way to stop generate parameterless constructor of entity class? RRS feed

  • Question

  • I want to manage the ef conxstr during runtime by my own code.

    ideally is to put in my code in the default parameter-less constructor.

    but the code generator keep auto gen this part:

        internal partial class MyEntities : DbContext
            public MyEntities()
                : base("name=MyEntities")
            { ...

    I want to code this constructor myself in separate cs file, as it's partial class.

    I cannot find option/setting related to this feature at the designer ui.

    is it doable?

    Friday, May 24, 2013 4:13 AM


  • Hi Kelmen,

    Unlike Code First, Model/Database First create the model with .edmx extension. The designer will add an connection string to app.config or web.config file. The code is generated to tell DbContext to use the connection string.

    As far as I know, there is no possibilities to stop generating the constructor from designer unless we manually modify the T4 template.

    Best regards,

    Chester Hong
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Kelmen Tuesday, May 28, 2013 8:18 AM
    Tuesday, May 28, 2013 6:32 AM