Is there an easy way to check wether an object is in objectscope?

7 posts, 1 answers
  1. Wolfgang
    Wolfgang avatar
    98 posts
    Member since:
    Oct 2012

    Posted 22 Mar 2013 Link to this post

    Is there an easy way to check wether an object is in objectscope?

    I search for something like:

    objectScope.ExistObject(object)
    or
    objectScope.ExistObjectID(OID);
    or 
    objectScopse.Contains(object/OID);

    Is such a thing available?
  2. Answer
    Ralph Waldenmaier
    Admin
    Ralph Waldenmaier avatar
    202 posts

    Posted 22 Mar 2013 Link to this post

    Hello Wolfgang,

    Yes it is available. You can use the following code to obtain already loaded instances.
     

    objectScope.LookupObjectById(oid);

    Hope this helps.
    Do come back in case you need further assistance.

    Greetings,
    Ralph
    the Telerik team
    Free Webinar: OpenAccess Integration in Sitefinity. SIGN UP NOW.
  3. DevCraft banner
  4. Wolfgang
    Wolfgang avatar
    98 posts
    Member since:
    Oct 2012

    Posted 22 Mar 2013 Link to this post

    Hi,
    thx.

    Maybe a small comment.

    If i search for LookupObjectByID I cannot find it in help (  http://www.telerik.com/help/search.aspx?q=LookupObjectById&ppId=638&pId=638&start=0 )

    In the google cache there still is some information ( http://webcache.googleusercontent.com/search?q=cache:BBdMbd76W40J:www.telerik.com/help/openaccess-orm/topic1228.html+openaccess+LookupObjectById&cd=1&hl=de&ct=clnk&gl=de )

    Is the method deprecated?

    Regards,
    Wolfgang


  5. Ralph Waldenmaier
    Admin
    Ralph Waldenmaier avatar
    202 posts

    Posted 22 Mar 2013 Link to this post

    Hello Wolfgang,

    You are right. This is due to the fact, that our API reference is not online at the moment. You can see the offline documentation for details, which also includes the API documentation. We will do our best to bring the API documentation back online, unfortunately, I can not provide you with at time frame yet.
    The mentioned method is not deprecated. 

    Feel free to ask if any other question arises.

    Regards,
    Ralph
    the Telerik team
    Free Webinar: OpenAccess Integration in Sitefinity. SIGN UP NOW.
  6. Wolfgang
    Wolfgang avatar
    98 posts
    Member since:
    Oct 2012

    Posted 29 May 2013 Link to this post

    Hi,

    I have not used the solution because i had some problems with it.

    I have made 2 methods, one with LookUpObjectByID, one with GetObjectByID (see below). While GetObject seems to be slower if an item could not be found and raises a NoSuchObjectException, LookUpObjectByID does not find valid elements.

    For example i do not change the db and do something like 

    bool existObject = IsObjectInObjectScope(aSourceObject_intID);
    
    bool existObject2 = IsObjectInObjectScope2(aSourceObject_intID));
    

    i get (always for the same object) 
    existObject = false and 
    existObject2 = true

    Funilly if i call (always for the same object) 
    bool existObject2 = IsObjectInObjectScope2(aSourceObject_intID));
    bool existObject = IsObjectInObjectScope(aSourceObject_intID);
    
    i get
    
    existObject = true and 
    existObject2 = true
    what would the objectscope need to find it with LookupObjectById?

    It's no matter of functionallity with IsObjectInObjectScope2, it's a matter of performance.

    best regards
    Wolfgang
    //method 1
         public bool IsObjectInObjectScope(IObjectId objectID)
            {
                try
                {
                    object test = this.objectScope.LookupObjectById(objectID);
                    return (null != test);
                }
                catch (Exception ex)
                {
                    return false;
                }
            }


    // method 2
     
               public bool IsObjectInObjectScope2(IObjectId objectId)
            {
                try
                {
                    Object test = this.objectScope.GetObjectById(objectId);
                    return (null != test);
                }
                catch (Telerik.OpenAccess.Exceptions.NoSuchObjectException nsoex)
                {
                    return false;
                }
                catch (Exception ex)
                {
                    return false;
                }
            }
     
    // method 1
            public bool IsObjectInObjectScope(IObjectId objectID)
            {
                try
                {
                    object test = this.objectScope.LookupObjectById(objectID);
                    return (null != test);
                }
                catch (Exception ex)
                {
                    return false;
                }
            }
     
    // method 1
            public bool IsObjectInObjectScope(IObjectId objectID)
            {
                try
                {
                    object test = this.objectScope.LookupObjectById(objectID);
                    return (null != test);
                }
                catch (Exception ex)
                {
                    return false;
                }
            }
  7. Ralph Waldenmaier
    Admin
    Ralph Waldenmaier avatar
    202 posts

    Posted 29 May 2013 Link to this post

    Hello Wolfgang,

    The behavior you described is expected. Let me explain why.
    With LookupObjectById you are asking the first level cache, if there is already an object with the provided OID loaded.
    With GetObjectById, we are first checking the cache if it is already loaded and if we don't find it in the cache, then the object will be loaded from the database. This is also the reason, why this method is slower, because it potentially needs to access the database.

    This means for your tests, that in the first setup you are checking the cache and then fetching the object from the database. The LookupByObjectId provides the correct answer, false in this case, because the object was not loaded so far. It will be loaded with the second call which then returns true, which is also right.

    In your second setup, you are first loading the object from the database and after this you are asking the cache if the object is still there. The results you see are then also correct, as the object was loaded before.

    I hope this information is helpful for you.
    Do come back in case you need further assistance.

    Regards,
    Ralph
    Telerik
    OpenAccess Samples Kit boasts 50+ sample applications providing diverse real-life business solutions. Click to read more and see OpenAccess ORM in action.
  8. Wolfgang
    Wolfgang avatar
    98 posts
    Member since:
    Oct 2012

    Posted 03 Jun 2013 Link to this post

    Thank you, that clarifies also some other things.
Back to Top
DevCraft banner