CodeSmith Community
Your Code. Your Way. Faster!

CanDeepSave bug in .netTiers v2.0.0.387 ( I think )

Latest post 03-18-2007 10:12 PM by nochangevn. 33 replies.
  • 10-10-2006 4:16 AM

    • GBR
    • Top 500 Contributor
    • Joined on 11-28-2005
    • Posts 17
    • Points 530

    CanDeepSave bug in .netTiers v2.0.0.387 ( I think )

    The official 2.0 release (v2.0.0.387) has been causing me some DeepSave problems.

     I think I found the source of the problem.  EntityProviderBaseCoreClass.generated.cst  contains a new helper method CanDeepSave.  The following section of code from CanDeepSave I belive contins a bug:


    else if ( deepSaveType == DeepSaveType.IncludeChildren )
        {
         if ( innerList.Contains(key) && innerList.HasProperty(entity, key, property) )
         {
          innerList.AddProperty(entity, key, property);
          return true;
         }
        }

    I think it should be as follows otherwise the innerList.AddProperty will never get hit. (note the "!"):

     else if ( deepSaveType == DeepSaveType.IncludeChildren )
        {
         if ( innerList.Contains(key) && !innerList.HasProperty(entity, key, property) )
         {
          innerList.AddProperty(entity, key, property);
          return true;
         }
        }

    Can anyone confirm this for me?

    • Post Points: 120
  • 10-10-2006 7:51 AM In reply to

    Re: CanDeepSave bug in .netTiers v2.0.0.387 ( I think )

    I have found the same bug in the CanDeepSave logic while working with a many-to-many relationship. The thread is here:

    http://community.codesmithtools.com/forums/thread/18625.aspx

    I've already tried the fix you suggested but it does not work for my simple many-to-many example. Unfortunately I've been side tracked and haven't had a chance to pursue this any further but it has been reported to the NetTiers group.

    Mike 

     

     

    • Post Points: 35
  • 10-10-2006 8:55 PM In reply to

    • GBR
    • Top 500 Contributor
    • Joined on 11-28-2005
    • Posts 17
    • Points 530

    Re: CanDeepSave bug in .netTiers v2.0.0.387 ( I think )

    Hi Mike,

    Does deep save work for your 1:N and 1:1 relationships (if you have any?). 

    DeepSave was not working for me at all, in any situation, even 1:N which I expect would have affected everyone using the official 2.0 relase. 

    My application has 1:N, N:N and 1:1 relationships.  All are working now after that change.  As a double check that the change actually took and was generated correctly you could compare the generated CanDeepSave and CanDeepLoad methods.  The logic in both should be similar. 

    Again ... I'm not sure how this is not affecting all DeepSave operations ... perhaps not many people have taken up the final 2.0 relase.

     -GBR

    • Post Points: 35
  • 10-10-2006 10:31 PM In reply to

    Re: CanDeepSave bug in .netTiers v2.0.0.387 ( I think )

    Earlier I had made the change you suggested but the many-to-many still does not persist.

    Here's why:

    - I call DeepSave for the student, the student is saved
    - Inside the student's DeepSave, the TeacherCollection_From_StudentTeacher DeepSave is called
    - The teachers are saved
    - Then the teachers are DeepSaved
    - The teacher's StudentTeacher collection is saved but this collection does not contain anything (I had loaded teachers into the student's StudentTeacher collection)
    - When control returns back to the student's DeepSave, the StudentTeacher CanDeepSave is called but returns false because the teacher already has handled the StudentTeachers
    - At this point I have a saved student and teacher but not StudentTeacher

    Unfortunately in my simple test case I don't have 1:1 or 1:n relationships but I would imagine those would persist fine using your suggested change.

    Mike 

     

    • Post Points: 5
  • 10-10-2006 10:53 PM In reply to

    Re: CanDeepSave bug in .netTiers v2.0.0.387 ( I think )

    I've got the complete fix now. Make your change and modify each DeepSave so that you only call CanDeepSave if there's something that needs to be saved.
    This eliminates the teacher snagging StudentTeacher when there's no StudentTeachers related to the teacher.

    One example of what I changed:
                            
    #region StudentCollection_From_StudentTeacher>
    if (entity.StudentCollection_From_StudentTeacher.Count > 0 || entity.StudentCollection_From_StudentTeacher.DeletedItems.Count > 0)
    {
        if (CanDeepSave(entity, "List<Student>", "StudentCollection_From_StudentTeacher", deepSaveType, innerList))
        {
            DataRepository.StudentProvider.DeepSave(transactionManager, entity.StudentCollection_From_StudentTeacher, deepSaveType, childTypes, innerList);
        }
    }
    #endregion

    This still does not handle every case though. For example if a student has some StudentTeachers and a teacher also has some different StudentTeachers. The first entity that saves will block all other entities from saving.

    Mike 

    • Post Points: 35
  • 10-19-2006 3:47 AM In reply to

    • adrianru
    • Top 500 Contributor
    • Joined on 04-10-2006
    • Posts 19
    • Points 455

    Re: CanDeepSave bug in .netTiers v2.0.0.387 ( I think )

    Howdy,

     Just thought I would say that I have hit some similar CanDeepSave problems.  It looks like the entity tracking is preventing that from deep save from completing all the way.  The entity tracking key remains the same and prevents all child entites in a collection from saving.

       I can post some more details if you are interested... currently too tired to think about it though.

     Adrian.

    • Post Points: 5
  • 10-24-2006 1:47 PM In reply to

    • bxuser
    • Not Ranked
    • Joined on 10-24-2006
    • Posts 2
    • Points 40

    Re: CanDeepSave bug in .netTiers v2.0.0.387 ( I think )

    I also have the exactly same problem :

    The CanDeepSave always return false.

     

     

    • Post Points: 35
  • 10-24-2006 2:43 PM In reply to

    Re: CanDeepSave bug in .netTiers v2.0.0.387 ( I think )

    I believe the same problem exists for DeepLoad. See Possible BUG : DeepLoad Annoyance

    At least I can never get any Childs of Children loaded. Always returns empty. Still haven't been updated on that progress hopefully NetTiers will read this and hopefully get back to us...

    • Post Points: 35
  • 10-24-2006 8:53 PM In reply to

    • GRAW
    • Top 25 Contributor
    • Joined on 06-23-2006
    • Posts 157
    • Points 4,560

    Re: CanDeepSave bug in .netTiers v2.0.0.387 ( I think )

    i got it to work, by modifying CanDeepSave, if anyone's interested.

    CanDeepSave() used to have this:

                    else if ( deepSaveType == DeepSaveType.IncludeChildren )
                    {
                        if ( innerList.Contains(key) && innerList.HasProperty(entity, key, property) )
                        {
                            innerList.AddProperty(entity, key, property);
                            return true;
                        }
                    }

     replace it with this:

                    else if ( deepSaveType == DeepSaveType.IncludeChildren )
                    {
                        if ( innerList.Contains(key) )
                        {
                            innerList.AddProperty(entity, key, property);
                            return true;
                        }
                    }

    I had gotten it to work at first by negating the result of innerList.HasProperty(), but that won't work 100% of the time.  I had a scenario where a DeepSave would still not work on some entities 2 levels down the hierarchy from the main entity being saved.  So let's say I was calling DeepSave on a Customer object which has a TList of Orders, each of which in turn has a TList of OrderLines.  It would save the TList<Order>, and the TList<OrderLine> of the first Order it seemed, but it would skip out on the TList<OrderLine> for the rest of the Orders.

    Very strange.... 

    "Small is the number of them that see with their own eyes, and feel with their own hearts" Albert Einstein
    • Post Points: 35
  • 10-24-2006 10:41 PM In reply to

    Re: CanDeepSave bug in .netTiers v2.0.0.387 ( I think )

    I just ran into the DeepSave problem tonight. Basically I have:

    Customer - 1:N relationship with AcceptedPayment

    Customer - 1:N relationship with Address.

    ---To save a new customer with an address:

    Customer newCustomer  = new Customer();

    .........set newCustomer properties

    Address newAddress  = new Address();

    ............set newAddress properties

    newCustomer.AddressCollection.Add(newAddress);

    Type[] typesToDeepSave = new Type[] { typeof(TList<Address>)};

    DataRepository.CustomerProvider.DeepSave(newCustomer, DeepSaveType.IncludeChildren, typesToDeepSave);

    The new address didn't get saved. After modifying the CanDeepSave as suggested above, it's saved!

    However, here is a strange problem that happens both before and after the fix...Even though I didn't specify AcceptedPaymentin my "typesToDeepSave",  the save would insert several rows of AcceptedPayment into the database. I haven't been able to trace it. I happened to came across this thread, so just wanted to see if anyone else had the same type of problem...BTW, I'm totally a .netTiers newbie, so any help would be very appreciated!

    • Post Points: 5
  • 10-26-2006 8:41 AM In reply to

    Re: CanDeepSave bug in .netTiers v2.0.0.387 ( I think )

    Does anyone know the last version of .NetTiers where deep saving was working?

     

     

    • Post Points: 35
  • 10-26-2006 9:21 AM In reply to

    Re: CanDeepSave bug in .netTiers v2.0.0.387 ( I think )

    I worked on this all yesterday and am close to a solution, hopefully i'll have something tested and posted for both DeepSave and DeepLoad by tomorrow.

    Robert Hinojosa
    -------------------------------------
    Member of the Codesmith Tools, .netTiers, teams
    http://www.nettiers.com
    -------------------------------------
    • Post Points: 65
  • 10-26-2006 9:38 AM In reply to

    Re: CanDeepSave bug in .netTiers v2.0.0.387 ( I think )

    Thanks Robert for working on this and getting back to us!!!

    -Chris

    • Post Points: 5
  • 11-01-2006 8:31 AM In reply to

    • GRAW
    • Top 25 Contributor
    • Joined on 06-23-2006
    • Posts 157
    • Points 4,560

    Re: CanDeepSave bug in .netTiers v2.0.0.387 ( I think )

    Robert,

    how's it going on this issue?  Making any headway? 

    "Small is the number of them that see with their own eyes, and feel with their own hearts" Albert Einstein
    • Post Points: 35
  • 11-10-2006 10:12 AM In reply to

    Re: CanDeepSave bug in .netTiers v2.0.0.387 ( I think )

    With CodeSmith 4.0 out the door, i've finally been able to have to some time to finish this.  And for being so patient with us, I added a nice treat.  There's one problem with composite primary keys on m2m that i'm trying to fix right quick before I post it.

     So this is what it looked like before.

        LeftTable left = new LeftTable();

        left.LeftColumnName = "MyLeftName2";

     

        RightTable right = new RightTable();

        right.RightColumnName = "MyRightName2";

     

        RightTable right2 = new RightTable();

        right2.RightColumnName = "MyRightName3";

     

        RightTable right3 = new RightTable();

        right3.RightColumnName = "MyRightName4";

     

        left.RightTableCollection_From_RightLeftJunction.Add(right);

        left.RightTableCollection_From_RightLeftJunction.Add(right2);

        left.RightTableCollection_From_RightLeftJunction.Add(right3);

     

        RightLeftJunction both = new RightLeftJunction();

        both.LeftColumn1PKSource = left;

        both.RightTablePKSource = right;

     

        RightLeftJunction both2 = new RightLeftJunction();

        both2.LeftColumn1PKSource = left;

        both2.RightTablePKSource = right2;

     

        RightLeftJunction both3 = new RightLeftJunction();

        both3.LeftColumn1PKSource = left;

        both3.RightTablePKSource = right3;

     

        left.RightLeftJunctionCollection.Add(both);

        left.RightLeftJunctionCollection.Add(both2);

        left.RightLeftJunctionCollection.Add(both3);

     

        using (TransactionManager tm = DataRepository.Provider.CreateTransaction())

        {

            tm.BeginTransaction();

            DataRepository.LeftTableProvider.DeepSave(tm, left);

            tm.Commit();

        }

     

    Now, there's no need if you don't want to create the junction entities.  The deep save method will automtically check the source objects and see if they exist or not, and create them if they do not exist.

    So this becomes:

        LeftTable left = new LeftTable();

        left.LeftColumnName = "MyLeftName2";

     

        RightTable right = new RightTable();

        right.RightColumnName = "MyRightName2";

     

        RightTable right2 = new RightTable();

        right2.RightColumnName = "MyRightName3";

     

        RightTable right3 = new RightTable();

        right3.RightColumnName = "MyRightName4";

     

        left.RightTableCollection_From_RightLeftJunction.Add(right);

        left.RightTableCollection_From_RightLeftJunction.Add(right2);

        left.RightTableCollection_From_RightLeftJunction.Add(right3);

     

        using (TransactionManager tm = DataRepository.Provider.CreateTransaction())

        {

            tm.BeginTransaction();

            DataRepository.LeftTableProvider.DeepSave(tm, left);

            tm.Commit();

        }

    This has been tested with a few databases that I have, but it would be great if you guys could give it a spin.


    I've changed the way the internals of the DeepSave work as well, they don't work off the keys and properties names anymore.  They just use a WeakReference to track if the collection or entity has been loaded.  I have not implemented this on the deep load just yet, wanted to verify all was well with DeepSave before I stuck my head in DeepLoad.  Should not be that difficult to implement.


    Robert Hinojosa
    -------------------------------------
    Member of the Codesmith Tools, .netTiers, teams
    http://www.nettiers.com
    -------------------------------------
    • Post Points: 155
Page 1 of 3 (34 items) 1 2 3 Next > | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems