OrientDB-NET - Select()
This method creates an OSqlSelect object, which you can use in querying the database.
Querying the Database
Eventually, you'll want to access the data that you're storing on OrientDB. This method allows you to construct a query to use in retrieving documents from the database.
Syntax
// RETRIEVE LIST
List<ODocument> ODatabase.Select(params string[] projections)
.From(target)
.ToList(string fetchplan)
// RETRIEVE STRING
string ODatabase.Select(params string[] projections)
.From(target)
.ToString()
projectionsDefines the columns you want returned.targetDefines the target you want to operate on.string targetWhere the target is a class or cluster.ORID targetWhere the target is a Record ID.OSqlSelect targetWhere the target is a nestedSelect()operation.ODocument targetWhere the target is the return value from another database operation.
fetch-planDefines the Fetching Strategy you want to use. If you want to issue the query without a fetching strategy, execute the method without passing it arguments.
Note that you can retrieve either a list of
ODocumentobjects or a string value.
The base Select() method operates on an OSqlSelect object, which provides additional methods for conditional and grouping operations. For more information on these additional methods, see Queries
Examples
This method supports two return values: strings and lists. In cases where you find you use on form more often than others, you might build a helper function to save yourself time and typing.
using Orient.Client;
using System;
// FETCH ALL DOCUMENTS BY CLASS
public List<ODocument> ClassFetch(ODatabase database, string className)
{
// LOG OPERATION
Console.WriteLine("Fetching Documents from: {0}", className);
// FETCH DOCUMENTS
return database.Select().From(className).ToList();
}
For classes that contain particularly large number of records, you might find it more useful to issue the query with a fetching strategy.
public List<ODocument> ClassFetch(ODatabase database,
string className, string fetchPlan)
{
// LOG OPERATION
Console.WriteLine("Fetching Documents from: {0}", className);
return database.Select().From(className).ToList(fetchPlan);
}
For more information on queries in OrientDB-NET, see Queries.