URGENT - Strange behaviour with databinded controls

Thread is closed for posting
4 posts, 0 answers
  1. Dusan
    Dusan avatar
    9 posts
    Member since:
    May 2013

    Posted 15 May 2013 Link to this post

    On the WinForm I have placed number of common controls (mostly textBoxes, comboBoxes and checkBoxes).
    I have also placed ObjectView and ObjectProvider controls and binded individual controls to an entity properties.

    Important note: I had to set advanced databindings to update the data source on property changed type to be able to see changes to entity data when user fills values.

    On form Load event I call the following code:

    var entity = new EntityCONTRACT(); // Domain Class instance
    SetInitialEntityValues(entity);    // populate some initial data
    DbContext.Add(entity);             // entity added to the context
    DbContext.FlushChanges();          // make entity data immediatelly available to the binded controls
    ObjectProvider1.Refresh();     // refresh data from underlying context
    ObjectView1.MoveLast();       // go to the last added entity

    Since according to internal application logic I need to copy values between the same entity's properties I always update the property as needed and subsequently call ObjectProvider1.Refresh() to see the changes in controls value.

    While this has been working for me on my development box, testers have reported loss of data in all data-bound controls on occassion. Usually after tabbing away from control. 

    Is there generally something wrong with my approach? Can this be caused by ObjectProvider1.Refresh() method call?

    I always try to search online documentation but in this case I have no clue.

    Please help as the implementation of OA ORM has been time costly and if I can't provide working solution I will have to turn to other ORM provider and scrape what I have done so far.

    Thank you very much,

  2. Dusan
    Dusan avatar
    9 posts
    Member since:
    May 2013

    Posted 16 May 2013 Link to this post


    Seems like the whole situation was caused by testers leaving program running unattended and the connection timed out...

    If there is a recommendation on how to handle cases like this other than setting time out to 0, please let me know.
  3. Viktor Zhivkov
    Viktor Zhivkov avatar
    324 posts

    Posted 17 May 2013 Link to this post

    Hello Dusan,

    The code that you have posted has some flaws that cause the connection timeout and can lead to more serious problems with transactions and locking when more concurrent users start to use your application.
    Calling FlushChanges should be avoided especially if the time period between FlushChanges and SaveChanges depends on user actions and can not be safely minimized. The reason is that FlushChanges will start a database transaction and this transaction will remain active and open until SaveChanges or ClearChanges is called. Setting the connection timeout will not solve the problem in this case.

    In addition you should be careful when calling MoveLast since this method can return not your new object but another one that is added by another concurrent user.
    If you are using the ObjectProvider to bind single item controls (like combobox or textbox and etc) I would suggest that you bind them manually in the Form_Loaded and Save_Click events.
    If you want to bind a data grid or list you can use the ObjectProvider or Bindling Source types.

    You can download OpenAccess Samples Kit to see an example how to use BindingSource component to bind a RadGrid (see CarSearchView class) and how to bind data for single entity (see CarInfoView and CarInfoController classes).

    If you need any further assistance, please let us know.

    All the best,
    Viktor Zhivkov
    the Telerik team
    OpenAccess Samples Kit boasts 50+ sample applications providing diverse real-life business solutions. Click to read more and see OpenAccess ORM in action.
  4. Dusan
    Dusan avatar
    9 posts
    Member since:
    May 2013

    Posted 19 May 2013 Link to this post

    Hi Victor,

    Thank you for enlightening me, now I certainly have a better insight into the OpenAccess ORM inner-workings.
    The only thing that I would like to add is that strangely enough the application in question is a single user only, therefore allowing me to program in a slightly awkward manner.
    Having said that I noted your remarks and will be aware of the potential problems that you have mentioned in the future.

Back to Top