Menu

Problem with new version.

2005-02-21
2013-03-07
  • victor Saquicela

    Hi,

    I have the next structure:
    A --OneToMany -- B

    I have two forms in VB.NET:
    In the first I can add B to A or create a new A.
    In the second only can add B to A.
    They are two forms of revenue of information for different users.

    The problem is that when I add object B in the second form, the first form does not have the new object B. The first form have a DataGrid the object B.
    With the previous version, it is correct. I think that the problem is in the cache, I am debugigng and in the second form the object A is correct, but when in the first form, I retrive object A and this doesn't have the same data that second Form.

    Saludos

    Victor

     
    • Richard Banks

      Richard Banks - 2005-02-21

      Hi Victor,

      Just to make sure I understand completely what is happening...

      1.  Form1 has an object A, with a data grid bound to the object B collection in Object A  (ie DataGrid1.DataSource = A.BCollection)

      2.  In Form1 you load obejct A, and the form populates the data grid.

      3.  In Form2 you also bring up object A, but this only allows new B objects to be added to the collection.

      4.  In Form2 you create a new B object add it to the collection.  You haven't actually saved object A yet.

      In the 2.0 version this would cause the data grid in Form1 to update since the collection contents have changed.  This is actually incorrect and shouldn't occur - you were making use of a flaw in the framework.

      In 2.0.1/2.1 this won't happen because collections are now treated as part of the parent object, instead of as separate objects.

      In 2.0 what would have happened is that the cache would have a copy of ObjA, including it's collection of B objects.  When you did a retrieve/find of ObjA in both Form1 and Form2 you would get different copies of ObjA, but both copies would reference the same collection of B obejcts.  In fact, changing the B collection would affect the collections of both the ObjA copies, as well as the collection stored in the cache!

      Under 2.0.1/2.1 when you retrieve ObjA in Form1 and Form2 you get two copies of ObjA as you would expect, but you also get two copies of the B collection.  Now when you change the B collection in Form1 it will not affect the cache, or the Form2 copy.

      Obviously if you save objectA in either form and then reload the objects in both Form1 and Form2 you will get the updated version of the object.

      If you want to automatically refresh the databinding in form1 when you update form2 then I would suggest you use either an event or call a shared method of form1 (in case you have multiple copies of the form displayed) to refresh and rebind the collection.

      I'm sorry the fix has caused you a bit more work.

      - Richard.

       
    • victor Saquicela

      Hi.

      I deal.

      now, With regard to:

      " Obviously if you save objectA in either form and then reload the objects in both Form1 and Form2 you will get the updated version of the object.  "

      It is incorrect. Because, in the form2 I add a object B, save object B. I when display form1, the object B does not appear in collection. If I delete cache and retrive the object A, this appear, but it isn't correct.

      Why not this the object B in the collection of the object A ?

      I think that exists two copies of A and two copies of the colleciones in cache.

      Why  not to support of the form that it was in the version 2.0 ???

      I think that is better, always to work with a copy of the object. This way the link with the controls serious mas easy.

      Saludos

      victor

       
      • Richard Banks

        Richard Banks - 2005-02-22

        > Why not this the object B in the collection of the object A ?

        I would think it's because the collection of B objects is referencing an old copy of B, not the new updated one.  This would be a bug and I'll have to see if I can duplicate the problem. The cache should only have one copy of the B object, and the collection should be referencing that copy.  Do you have a unit test that shows the problem?

        > Why not to support of the form that it was in the version 2.0 ??? 

        Version 2.0 was broken in terms of cache integrity.  If you amended the B collection of object A, the cache was updated regardless of wether object A was saved or not.  This means that if you were doing a transaction, and rolledback the changes without saving objectA then the B collection would still be in a modified state.

        Another issue is this - should collections in objects get treated as a values or objects when copying?

        I'm of the firm opinion that most programmers treat collections in their class definitions like values.  What I mean is that they would expect the following code to result in the collections being different.

        ObjA2 = ObjA1.Copy
        ObjA2.BCollection.Delete(1)
        If ObjA1.BCollection.Count <> ObjA2.BCollection.Count Then
          Debug.Writeline("Expected result")
        Else
          Debug.Writeline("Not expected result")
        End If

        - Richard.

         
    • Nobody/Anonymous

      Hi,

      I don't have unit test. I am trying discovery the problem.

       
    • Nobody/Anonymous

      I do not understand that happen.  In the form2 the object A have 3 objects B (saved), and in form1 the object A have 2 objects B. If I reload all objects, the form1 is correct. is it problem the cache ?

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.