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

Access to the scope object from inside a persistent class' method

2 Answers 67 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.
Tomasz M.Lipiński
Top achievements
Rank 1
Tomasz M.Lipiński asked on 08 Apr 2010, 10:06 PM
Hi,

Let's assume that my persistent class inherits and implements the IInstanceCallbacks interface. I would like to do slightly different things while creating a new object and while modifying an existing one. I don't want to distinguish new and existing objects checking some properties for specific values (e.g. 0 for autoincrement identity). Outside the object I can use the scope object: scope.IsNew(persistent object) but when executing PreStore method (for example) I haven't got the scope object. This leads to this topic's title: the object is always maintained using some IObjectScope object; how (if ever) can I get this object being "inside" the persistent object?

Regards
Tomasz

2 Answers, 1 is accepted

Sort by
0
Accepted
Damyan Bogoev
Telerik team
answered on 09 Apr 2010, 03:02 PM
Hello Tomasz M.LipiƄski,

You can use the Database.GetContext(persistentCapableObject) method to achieve this. The GetContext method returns the object scope instance managing the passed object. In your case you should do the following:
IObjectScope scope = Database.GetContext(this) as IObjectScope;
Hope that helps.

Greetings,
Damyan Bogoev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Tomasz M.Lipiński
Top achievements
Rank 1
answered on 09 Apr 2010, 10:24 PM
Great, that's it!.

Thanks and regards
Tomasz
Tags
General Discussions
Asked by
Tomasz M.Lipiński
Top achievements
Rank 1
Answers by
Damyan Bogoev
Telerik team
Tomasz M.Lipiński
Top achievements
Rank 1
Share this question
or