I search for something like:
objectScope.ExistObject(object)
or
objectScope.ExistObjectID(OID);
or
objectScopse.Contains(object/OID);
Is such a thing available?
6 Answers, 1 is accepted
Yes it is available. You can use the following code to obtain already loaded instances.
objectScope.LookupObjectById(oid);
Do come back in case you need further assistance.
Greetings,
Ralph
the Telerik team
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
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.
Ralph
the Telerik team
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 andexistObject2 = true
Funilly if i call (always for the same object)
bool existObject2 = IsObjectInObjectScope2(aSourceObject_intID));
bool existObject = IsObjectInObjectScope(aSourceObject_intID);
i getexistObject = true andwhat would the objectscope need to find it with LookupObjectById?existObject2 = true
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
;
}
}
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.
Ralph
Telerik