You are here: Platform Specific Issues > Disconnected Objects > Comparison Of Different IDs > Example Internal Id

Example Internal Id

This example demonstrates how you can use internal object ids to identify objects across objects containers. Take a look advantages and disadvantages of internal ids: See "Comparison Of Different IDs"

For using the internal ids no additional configuration is required. You can get this id for any object.

You can get the internal id from the extended object container.

long interalId = container.Ext().GetID(obj);
Db4oInternalIdExample.cs: get the db4o internal ids
Dim interalId As Long = container.Ext().GetID(obj)
Db4oInternalIdExample.vb: get the db4o internal ids

Getting a object by its id is also easy. First you get the object from the container. Unlike queries this won't return a activated object. So you have to do it explicitly.

long internalId = idForObject;
object objectForID = container.Ext().GetByID(internalId);
// getting by id doesn't activate the object
// so you need to do it manually
container.Ext().Activate(objectForID);
Db4oInternalIdExample.cs: get an object by db4o internal id
Dim internalId As Long = idForObject
Dim objForID As Object = container.Ext().GetByID(internalId)
' getting by id doesn't activate the object
' so you need to do it manually
container.Ext().Activate(objForID)
Db4oInternalIdExample.vb: get an object by db4o internal id