This example demonstrates how you can use Guids to identify objects across objects containers. Take a look advantages and disadvantages of Guids: See "Comparison Of Different IDs"
This example assumes that all object have a common super-class, IDHolder, which holds the Guid in a field.
private readonly Guid guid = Guid.NewGuid(); public Guid ObjectId { get { return guid; } }
Private ReadOnly guid As Guid = Guid.NewGuid() Public ReadOnly Property ObjectId() As Guid Get Return guid End Get End Property
It's important to index the id-field, otherwise looking up for object by id will be slow.
configuration.Common.ObjectClass(typeof (IDHolder)).ObjectField("guid").Indexed(true);
configuration.Common.ObjectClass(GetType(IDHolder)).ObjectField("guid").Indexed(True)
The id is hold by the object itself, so you can get it directly.
IDHolder uuidHolder = (IDHolder) obj; Guid uuid = uuidHolder.ObjectId;
Dim uuidHolder As IDHolder = DirectCast(obj, IDHolder) Dim uuid As Guid = uuidHolder.ObjectId
You can get the object you can by a regular query.
IDHolder instance = container.Query(delegate(IDHolder o) { return o.ObjectId.Equals(idForObject); })[0];
Dim instance As IDHolder = container.Query(Function(o As IDHolder) o.ObjectId.Equals(idForObject))(0)