This is a migrated thread and some comments may be shown as answers.

Loading Single Object - refresh

3 Answers 52 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
devoas
Top achievements
Rank 1
devoas asked on 29 Dec 2009, 02:07 PM
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







3 Answers, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 04 Jan 2010, 10:00 AM
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.
0
devoas
Top achievements
Rank 1
answered on 04 Jan 2010, 11:12 AM
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
0
Alexander
Telerik team
answered on 04 Jan 2010, 12:40 PM
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.
Tags
General Discussions
Asked by
devoas
Top achievements
Rank 1
Answers by
Alexander
Telerik team
devoas
Top achievements
Rank 1
Share this question
or