Loading Single Object - refresh

Thread is closed for posting
4 posts, 0 answers
  1. devoas
    devoas avatar
    71 posts
    Member since:
    Dec 2009

    Posted 29 Dec 2009 Link to this post

    Hi,

    I am using scope.GetObjectById(oid) to load single Object.  How would I know that this is been retrieved from context or from Database, Do I need to refresh it or not......

    Suppose I load Customer by following code..

                IObjectId oid = Database.OID.ParseObjectId(typeof(Customer), "1");
    var record = (Customer)scope.GetObjectById(oid);
        .
        .
        .
        after few mins, I again call above code to get same object which was been modified by another user...

        How can I find if I need scope.refresh to get latest copy or not......    as If I cannot find and write   scope.Refresh(record);
        then for most of the cases, data will be retrieved from Database twice.

    Thanks,
    devoas







  2. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 04 Jan 2010 Link to this post

    Hi devoas,

    I am afraid this is not possible. Even if you have a version field in the class, a roundtrip to the database will be necessary in order to read the latest version value.
    Note that as an alternative to the scope.Refresh() method you can do the reading within an active transaction. This would ensure that you are working with the latest data as well.

    Sincerely yours,
    Alexander
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. devoas
    devoas avatar
    71 posts
    Member since:
    Dec 2009

    Posted 04 Jan 2010 Link to this post

    Dear Alexander

    Thanks alot.

    Please just confirm do I need to commit the active transaction after loading the Data or just Begin, Read and rollback active Transaction.

    Thanks,
    devoas
  4. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 04 Jan 2010 Link to this post

    Hello devoas,

    You do not need to commit the transaction if you have not made any changes. A rollback would be enough to end the transaction in such cases.

    All the best,
    Alexander
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top