|
using System;
using System.Collections.Generic;
using Db4objects.Db4o;
namespace DataAccess
{
/// <summary>
/// Native query class.
/// </summary>
class NativeQueryAction<GenericType> : IQueryAction<GenericType>
where GenericType : class
{
private Predicate<GenericType> matchPredicate;
/// <summary>
/// The depth of the query in the objects' graph.
/// </summary>
private int queryDepth;
/// <summary>
/// NativeQueryAction constructor.
/// </summary>
/// <param name="matchPredicate"></param>
/// <param name="queryDepth">The depth of the query in the objects' graph</param>
public NativeQueryAction(Predicate<GenericType> matchPredicate, int queryDepth)
{
this.matchPredicate = matchPredicate;
this.queryDepth = queryDepth;
}
/// <summary>
/// Performs a query for data against the database.
/// </summary>
/// <param name="db">The database handle</param>
/// <returns>The collection of objects retrieved by the query</returns>
public IList<GenericType> PerformQuery(IObjectContainer db)
{
IList<GenericType> resultObjects = new List<GenericType>();
IList<GenericType> queryResults = db.Query<GenericType>(matchPredicate);
foreach (GenericType currentObject in queryResults)
{
db.Activate(currentObject, queryDepth);
resultObjects.Add(currentObject);
}
return resultObjects;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.