Prevent compiler to stop undo my changes in T4 classes Entity Framework











up vote
0
down vote

favorite












I am using Entity Framework and want to do some changes in context class



For ex. I am creating one more constructor for connection string but issue is every time when I open .edmx file and save it, then my changes are no longer exist.



Is there any way for me to tell .edmx not to undo my changes in context class or T4 classes?










share|improve this question




























    up vote
    0
    down vote

    favorite












    I am using Entity Framework and want to do some changes in context class



    For ex. I am creating one more constructor for connection string but issue is every time when I open .edmx file and save it, then my changes are no longer exist.



    Is there any way for me to tell .edmx not to undo my changes in context class or T4 classes?










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am using Entity Framework and want to do some changes in context class



      For ex. I am creating one more constructor for connection string but issue is every time when I open .edmx file and save it, then my changes are no longer exist.



      Is there any way for me to tell .edmx not to undo my changes in context class or T4 classes?










      share|improve this question















      I am using Entity Framework and want to do some changes in context class



      For ex. I am creating one more constructor for connection string but issue is every time when I open .edmx file and save it, then my changes are no longer exist.



      Is there any way for me to tell .edmx not to undo my changes in context class or T4 classes?







      entity-framework t4






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 19 at 16:14









      Cœur

      17k9102140




      17k9102140










      asked Mar 31 '15 at 5:10









      Parveen

      2261218




      2261218
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          5
          down vote













          You cannot change the generated code. You can add things to it since the classes that are generated are partial classes.



          Add your additions to a separate file containing the custom part of the partial class.



          See here: https://msdn.microsoft.com/en-us/library/wa80x488.aspx






          share|improve this answer





















          • Thanks alot . It is very helpful.
            – Parveen
            Mar 31 '15 at 5:21


















          up vote
          0
          down vote













          An alternative is to modify the T4 template yourself and consistently apply your specific needs to the generated classes.
          It is common practice to do this when for example you want INotifyPropertyChanged as interface on every class.
          This approach only works if your changes are generic in nature. If you want to do a specific change in only one class then this solution does not work for you.



          Another alternative is to take full control of the classes by using code first.
          You can mark the methods and properties with special attributes to map them to the db. And there is a reverse engineering option to create these classes from an existing db. You would reverse engineer once, and then take control of the classes and tweak them to your needs



          I generally take the last approach myself right now, because it is not using partial classes all code that belongs to a class is all in the same file.



          The answer of Maarten is also fine, but there are 2 more options.






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f29361008%2fprevent-compiler-to-stop-undo-my-changes-in-t4-classes-entity-framework%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            5
            down vote













            You cannot change the generated code. You can add things to it since the classes that are generated are partial classes.



            Add your additions to a separate file containing the custom part of the partial class.



            See here: https://msdn.microsoft.com/en-us/library/wa80x488.aspx






            share|improve this answer





















            • Thanks alot . It is very helpful.
              – Parveen
              Mar 31 '15 at 5:21















            up vote
            5
            down vote













            You cannot change the generated code. You can add things to it since the classes that are generated are partial classes.



            Add your additions to a separate file containing the custom part of the partial class.



            See here: https://msdn.microsoft.com/en-us/library/wa80x488.aspx






            share|improve this answer





















            • Thanks alot . It is very helpful.
              – Parveen
              Mar 31 '15 at 5:21













            up vote
            5
            down vote










            up vote
            5
            down vote









            You cannot change the generated code. You can add things to it since the classes that are generated are partial classes.



            Add your additions to a separate file containing the custom part of the partial class.



            See here: https://msdn.microsoft.com/en-us/library/wa80x488.aspx






            share|improve this answer












            You cannot change the generated code. You can add things to it since the classes that are generated are partial classes.



            Add your additions to a separate file containing the custom part of the partial class.



            See here: https://msdn.microsoft.com/en-us/library/wa80x488.aspx







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 31 '15 at 5:12









            Maarten

            18.5k33354




            18.5k33354












            • Thanks alot . It is very helpful.
              – Parveen
              Mar 31 '15 at 5:21


















            • Thanks alot . It is very helpful.
              – Parveen
              Mar 31 '15 at 5:21
















            Thanks alot . It is very helpful.
            – Parveen
            Mar 31 '15 at 5:21




            Thanks alot . It is very helpful.
            – Parveen
            Mar 31 '15 at 5:21












            up vote
            0
            down vote













            An alternative is to modify the T4 template yourself and consistently apply your specific needs to the generated classes.
            It is common practice to do this when for example you want INotifyPropertyChanged as interface on every class.
            This approach only works if your changes are generic in nature. If you want to do a specific change in only one class then this solution does not work for you.



            Another alternative is to take full control of the classes by using code first.
            You can mark the methods and properties with special attributes to map them to the db. And there is a reverse engineering option to create these classes from an existing db. You would reverse engineer once, and then take control of the classes and tweak them to your needs



            I generally take the last approach myself right now, because it is not using partial classes all code that belongs to a class is all in the same file.



            The answer of Maarten is also fine, but there are 2 more options.






            share|improve this answer

























              up vote
              0
              down vote













              An alternative is to modify the T4 template yourself and consistently apply your specific needs to the generated classes.
              It is common practice to do this when for example you want INotifyPropertyChanged as interface on every class.
              This approach only works if your changes are generic in nature. If you want to do a specific change in only one class then this solution does not work for you.



              Another alternative is to take full control of the classes by using code first.
              You can mark the methods and properties with special attributes to map them to the db. And there is a reverse engineering option to create these classes from an existing db. You would reverse engineer once, and then take control of the classes and tweak them to your needs



              I generally take the last approach myself right now, because it is not using partial classes all code that belongs to a class is all in the same file.



              The answer of Maarten is also fine, but there are 2 more options.






              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                An alternative is to modify the T4 template yourself and consistently apply your specific needs to the generated classes.
                It is common practice to do this when for example you want INotifyPropertyChanged as interface on every class.
                This approach only works if your changes are generic in nature. If you want to do a specific change in only one class then this solution does not work for you.



                Another alternative is to take full control of the classes by using code first.
                You can mark the methods and properties with special attributes to map them to the db. And there is a reverse engineering option to create these classes from an existing db. You would reverse engineer once, and then take control of the classes and tweak them to your needs



                I generally take the last approach myself right now, because it is not using partial classes all code that belongs to a class is all in the same file.



                The answer of Maarten is also fine, but there are 2 more options.






                share|improve this answer












                An alternative is to modify the T4 template yourself and consistently apply your specific needs to the generated classes.
                It is common practice to do this when for example you want INotifyPropertyChanged as interface on every class.
                This approach only works if your changes are generic in nature. If you want to do a specific change in only one class then this solution does not work for you.



                Another alternative is to take full control of the classes by using code first.
                You can mark the methods and properties with special attributes to map them to the db. And there is a reverse engineering option to create these classes from an existing db. You would reverse engineer once, and then take control of the classes and tweak them to your needs



                I generally take the last approach myself right now, because it is not using partial classes all code that belongs to a class is all in the same file.



                The answer of Maarten is also fine, but there are 2 more options.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 31 '15 at 6:53









                Philip Stuyck

                6,14131733




                6,14131733






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f29361008%2fprevent-compiler-to-stop-undo-my-changes-in-t4-classes-entity-framework%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    404 Error Contact Form 7 ajax form submitting

                    How to know if a Active Directory user can login interactively

                    Refactoring coordinates for Minecraft Pi buildings written in Python