If we have a prototype and want to find out if there is an object in the database with the same field values, we can simply use QBE:
01private static void RetrieveEqual() { 02
IObjectContainer container = Database(); 03
if (container != null) { 04
try { 05
IObjectSet result = container.Get(new Pilot("Kimi Raikkonnen", 100)); 06
if (result.Count > 0){ 07
System.Console.WriteLine("Found equal object: " + result.Next().ToString()); 08
} else { 09
System.Console.WriteLine("No equal object exist in the database"); 10
} 11
} catch (Exception ex) { 12
System.Console.WriteLine("System Exception: " + ex.Message); 13
} finally { 14
CloseDatabase(); 15
} 16
} 17
}
01Private Shared Sub RetrieveEqual() 02
Dim container As IObjectContainer = Database() 03
If container IsNot Nothing Then 04
Try 05
Dim result As IObjectSet = container.[Get](New Pilot("Kimi Raikkonnen", 100)) 06
If result.Count > 0 Then 07
System.Console.WriteLine("Found equal object: " + result.[Next]().ToString()) 08
Else 09
System.Console.WriteLine("No equal object exist in the database") 10
End If 11
Catch ex As Exception 12
System.Console.WriteLine("System Exception: " + ex.Message) 13
Finally 14
CloseDatabase() 15
End Try 16
End If 17
End Sub
This method allows to combine retrieval and comparing in one operation.