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

Thread is closed for posting
3 posts, 1 answers
  1. Tomasz M.Lipiński
    Tomasz M.Lipiński avatar
    71 posts
    Member since:
    Nov 2009

    Posted 08 Apr 2010 Link to this post

    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. Answer
    Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 09 Apr 2010 Link to this post

    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.
  3. Tomasz M.Lipiński
    Tomasz M.Lipiński avatar
    71 posts
    Member since:
    Nov 2009

    Posted 09 Apr 2010 Link to this post

    Great, that's it!.

    Thanks and regards
    Tomasz
Back to Top