CodeSmith Community
Your Code. Your Way. Faster!

Update .nettiers after change database structure

Latest post 05-16-2008 10:26 PM by SuperJeffe. 6 replies.
  • 05-15-2008 9:42 PM

    • Aragon
    • Not Ranked
    • Joined on 01-15-2008
    • Posts 8
    • Points 190

    Update .nettiers after change database structure

    Hi,

    I used CodeSmith and .nettiers to generate whole project from SQL Server 2005 database  call "MyDatabase". In this database, it has a table tblOffender with fields:

    Table: tblOffender

        Field 1: Offender_ID

        Field 2: First_Name

        Field 3: Last_Name

        Field 4: Country_Of_Birth

        Filed 5: Status

    - Now, I deleted the column "Country_Of_Birth" in database. I know that I need do some update in Store Procedures as well as Business Layer.

    I found in the database have those store procedure use the deleted column "Country_Of_Birth":

                + tblOffender_Find

                + tblOffender_Get_List

                + tblOffender_GetPaged

                + tblOffender_Insert

     - I also found in business layer has these classes involve the field "Country_Of_Birth":

               + IOffender.cs

               + Offender.cs

               + OffenderBase.generated.cs

    In  Data.SqlClient layer

               + SqlOffenderProvider.cs

               + SqlOffenderProviderBase.generated.cs

               + OffenderProviderBase.cs

               + OffenderProviderBase.generatedCore.cs

    And some webforms in website level.

     

    The question here is that which below option should I use:

    Option 1: Manually modify the change in these store procedures or the above classes in order to keep the code working.

    Option 2: Use .nettier & CodeSmith to generate whole project again.

     With Option 1, it would cost time and raise many bugs later. In addtion, this option seems to be unrealistic if the database schema change frequency.

     With Option 2, I tried to regenerated code again but this action will overwrite all my changes on other webforms with I want to keep those changes.

     How can I update only webforms,  bussiness classes, provider relevant with tblOffender only?

     

    Generally, the question could be how to update source code (generated by .nettiers) when we change data structure?

     

    Looking forward to any help or any idea.

    Aragon 

     

    • Post Points: 65
  • 05-15-2008 10:42 PM In reply to

    • SuperJeffe
    • Top 25 Contributor
    • Joined on 05-05-2006
    • Tulsa, Ok
    • Posts 332
    • Points 8,380

    Re: Update .nettiers after change database structure

    Well, typically with Generated code, as a rule of thumb, never change what it outputs.  Nettiers provides classes at almost every level for you to insert your code or override what was generated.  You never want to modify any file that has a .generated name to it.  Same with the stored procs, they are a never touch in our shop.  Try and change the Templates to generate what you want.  We have multiple people re-generating code in our shop each day.  The whole benefit to the generated code is you shouldn't have to do the #1 ever again.  I know for a fact, from the service level down, Nettiers provides classes that inherit from the .generated classes for you to place your code.

    With the web UI, you don't get alot of visual inheritance.  So if you have taken the little admin site it generates and modified it, you are probably in a little trouble.  Again, not knowing what you have changed it is hard for me to know and to tell you with certainty what will happen.  You could choose not to re-generate the Admin web site and then just manually modify it to fix any compilation errors, but again, this is not the "recommended" way to use Nettiers.

    jeff

    ----------------------------------------------------------------------
     Member of the .NetTiers team | Visit http://www.nettiers.com
    ----------------------------------------------------------------------

    • Post Points: 5
  • 05-16-2008 2:19 AM In reply to

    • swin
    • Top 10 Contributor
    • Joined on 06-14-2006
    • London, UK
    • Posts 922
    • Points 34,710

    Re: Update .nettiers after change database structure

     I agree with superJeffe - you should never have to do #1.

    What I've done at my site is modify the website templates to give us a look and feel that fits in with the rest of our site. We regenerate the web admin along with the other classes, but only copy new or significantly changed existing files to our main development directory.  This gives us flexability and control.

    hth

    swin 

    ------------------------------------------------- Member of the .NetTiers team -------------------------------------------------
    • Post Points: 35
  • 05-16-2008 10:37 AM In reply to

    • vbandrade
    • Top 25 Contributor
    • Joined on 09-27-2007
    • Brasil
    • Posts 236
    • Points 5,955

    Re: Update .nettiers after change database structure

    On #1 everyone agrees.

     

    About #2 I have a **very** strong feeling about the generated website. You should never use it.  the web site is great to test changes in the script. I use it a lot to validate my changes. But never as an administrative tool to my projects.

     

    I said it was a strong feeling (;

     

    [s 

    • Post Points: 35
  • 05-16-2008 1:34 PM In reply to

    • SuperJeffe
    • Top 25 Contributor
    • Joined on 05-05-2006
    • Tulsa, Ok
    • Posts 332
    • Points 8,380

    Re: Update .nettiers after change database structure

    Haha, IT people aren't known for there opinions are they Surprise

     jeff

    ----------------------------------------------------------------------
     Member of the .NetTiers team | Visit http://www.nettiers.com
    ----------------------------------------------------------------------

    • Post Points: 35
  • 05-16-2008 10:11 PM In reply to

    • Aragon
    • Not Ranked
    • Joined on 01-15-2008
    • Posts 8
    • Points 190

    Re: Update .nettiers after change database structure

    Thanks for your response mates.

     

    #2: It seem that this is a solution everyone refer.

     

    However, I modified many things in other web forms. Therefore, I don’t want regenerating whole project, while this action will overwrite all my modified webforms in my current project folder (I call this is folder A). 

     

    I choice to regenerate the only table tblOffender in which I deleted CountryOfBirth column . In order to do that, I set the output folder to new folder B, so the regenerating action will not auto overwriting my current project.

     

    Then, I want to manually overwrite some web forms and classed which are relevant with tblOffender. I will copy them from folder B (have just regenerated) to folder A (current project)

     

    The problem with me that I don’t know exactly what webforms (in web font-end; web admin), classes (component layer) should I manually overwrite?

     

    Am I right if I approach the problem this way? This situation we will face many times when we develop new project, when the database usually add new table, new column or drop table, drop column, change relationship …

     

    What should I do?

     

     

     

    #1: It seems that this option should not be the choice.

     

     However, if someone likes to discuss more with me, please read. If not, please ignore this below text.

     

     ------------------------------------------------------

    I found this line in generated class  (OffenderBase.generated.cs):

    /*

          Important: Do not modify this file. Edit the file Offender.cs instead.

    */

     

    However, in this class I found a property of Country of Birth as below:

     

                /// <summary>

                ///   Gets or sets the CountryOfBirth property.

                ///        

                /// </summary>

                /// <value>This type is smallint.</value>

                /// <remarks>

                /// This property can be set to null.

                /// If this column is null, this property will return (short)0. It is up to the developer

                /// to check the value of IsCountryOfBirthNull() and perform business logic appropriately.

                /// </remarks>

                [DescriptionAttribute(""), System.ComponentModel.Bindable( System.ComponentModel.BindableSupport.Yes)]

                [DataObjectField(false, false, true)]

                public virtual System.Int16? CountryOfBirth

                {

                      get

                      {

                            return this.entityData.CountryOfBirth;

                      }

                     

                      set

                      {

                            if (this.entityData.CountryOfBirth == value)

                                  return;

                                 

                            OnColumnChanging(OffenderColumn.CountryOfBirth, this.entityData.CountryOfBirth);

                            this.entityData.CountryOfBirth = value;

                            if (this.EntityState == EntityState.Unchanged)

                                  this.EntityState = EntityState.Changed;

                            OnColumnChanged(OffenderColumn.CountryOfBirth, this.entityData.CountryOfBirth);

                            OnPropertyChanged("CountryOfBirth");

                      }

                }

     

     

     

    In my current database, this column is no longer exist. How can I reflect the change in database level into component layer as well as web font-end layer without touch in this generated class? Is there any way to modify Offender.cs only to reflect the change?

     ------------------------------------------------------

     

    • Post Points: 35
  • 05-16-2008 10:26 PM In reply to

    • SuperJeffe
    • Top 25 Contributor
    • Joined on 05-05-2006
    • Tulsa, Ok
    • Posts 332
    • Points 8,380

    Re: Update .nettiers after change database structure

    Well, as far as manually merging, you could try to use some utility like WinMerge to merge the 2 files together.  That's just a thought.  But again, moving forward I would avoid this.  What you could do is copy the web project to another directory, let it generate the web project and then see what breaks in your old one.

    There isn't any way to do this.  I don't even want to get into all it would take to manually delete the column from code.  This is just something that shouldn't be happening.  Rule of thumb has to be to never modify the generated code.

    I know it seems your stuck....my suggestion is take the pain now and fix the web site to not get overwritten.  You are just going to have to manually maintain the web site from here on out.  Let Nettiers generate everthing else but the website and at least that gets you most of the way there.

    jeff

    ----------------------------------------------------------------------
     Member of the .NetTiers team | Visit http://www.nettiers.com
    ----------------------------------------------------------------------

    • Post Points: 5
Page 1 of 1 (7 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems