You are here: Basics Operations & Concepts > Querying > Query By Example

Query By Example

Query By Example is a very special query method. Basically you pass in a example object to db4o. Then db4o searches the database for all objects which look alike.

The basic principal is like this. It goes through all fields of the example object. If a field doesn't have the default value it is used as constraint. It takes that value and checks for all objects which have an equal value for this field. If more than one field has a value, each value is used as constraint and combined. Here's a simple example.

Pilot theExample = new Pilot();
theExample.Name = "John";
IList result = container.QueryByExample(theExample);
QueryByExamples.cs: Query for John by example
Dim theExample As New Pilot()
theExample.Name = "John"
Dim result As IList = container.QueryByExample(theExample)
QueryByExamples.vb: Query for John by example

Take a look a the various examples of query by example examples. See "Query By Example Examples"

Query by Example has fundamental limitations, which limits its use cases. See "Query By Example Limitations"