IQuery |
public interface IQueryResultSet<TData> : IQueryResultSet, IEnumerable, IEnumerable<TData>
[Missing <typeparam name="TData"/> documentation for "T:SanteDB.Core.Model.Query.IQueryResultSet`1"]
The IQueryResultSetTData type exposes the following members.
| Name | Description | |
|---|---|---|
| ElementType |
Gets the types of elements which can be filtered and/or manipulated in the collection
(Inherited from IQueryResultSet) |
| Name | Description | |
|---|---|---|
| Any |
Returns true if any results match
(Inherited from IQueryResultSet) | |
| AsStateful | Get the result set as a stateful query | |
| Count |
Return only the count of the objects
(Inherited from IQueryResultSet) | |
| Distinct | Get only distinct objects in the collection | |
| Except | Do not include in the result set any objects which match the query | |
| First | Retrieve the first result otherwise throw exception | |
| FirstOrDefault | Retrieve the first result otherwise return default | |
| GetEnumerator | Returns an enumerator that iterates through a collection. (Inherited from IEnumerable) | |
| Intersect(ExpressionFuncTData, Boolean) | Intersect this result set with another | |
| Intersect(IQueryResultSet) |
Intersect this set and other (Inherited from IQueryResultSet) | |
| Intersect(IQueryResultSetTData) | Intersect this result set with another | |
| OfTypeTType |
Flatten this object model to an IEnumerable of type TType (Inherited from IQueryResultSet) | |
| SelectTReturn(Expression) |
Select a single object from the object
(Inherited from IQueryResultSet) | |
| SelectTReturn(ExpressionFuncTData, TReturn) | Select a single object from the object | |
| Single | Retrieve one (and only one) result otherwise throw exception | |
| SingleOrDefault | Retrieve one (and only one) otherwise return null if not found or throw if more than one | |
| Skip | Skip count results | |
| Take | Take only count results | |
| Union(ExpressionFuncTData, Boolean) | Union the results in this set with those matching query | |
| Union(IQueryResultSet) |
Union this set and other (Inherited from IQueryResultSet) | |
| Union(IQueryResultSetTData) | Union the results in this set with those in the other | |
| Where(Expression) |
Filter the result set where the specified condition matches
(Inherited from IQueryResultSet) | |
| Where(ExpressionFuncTData, Boolean) | Filter the result set where the specified condition matches |
| Name | Description | |
|---|---|---|
| ApplyResultInstructions |
Apply result instructions
(Defined by QueryControlUtility) | |
| AsResultSet |
As result set
(Defined by ExtensionMethods) | |
| AsResultSetTData |
As result set
(Defined by ExtensionMethods) | |
| ForEachTData |
For each item in an enumerable
(Defined by ExtensionMethods) | |
| IsNullOrEmpty |
Returns true if the IList is null or has no elements
(Defined by ExtensionMethods) | |
| OrderByTData, TKey |
Order result set
(Defined by ExtensionMethods) | |
| OrderByDescendingTData, TKey |
Order result set
(Defined by ExtensionMethods) | |
| ToDictionaryIgnoringDuplicatesTData, TKey |
Creates a DictionaryTKey, TValue from an IEnumerableT
according to specified key selector function. Diplicate keys will not be added to the dictionary.
(Defined by ExtensionMethods) | |
| ToDictionaryIgnoringDuplicatesTData, TKey, TElement |
Creates a DictionaryTKey, TValue from an IEnumerableT
according to specified key selector and element selector functions. Diplicate keys will not be added to the dictionary.
(Defined by ExtensionMethods) | |
| TransformResultSetTFrom, TTo |
As a result set
(Defined by ExtensionMethods) |
Implementers of this interface support yielded or late-executed queries. For example, when calling a Query() method on a persistence class, the query to the database is not executed immediately, rather the first call to a method which iterates over this collection, or calls or otherwise fetches a record results in the query being executed
This is done to reduce the amount of data which is loaded from the database, however it also means that careless use of the result set will result in many additional queries to the database. Consider:
var results = this.persistenceService.Query(o => o.StatusConceptKey == StatusKeys.Active, AuthenticationContext.Current.Principal); var count = results.Count(); var first = results.First(); var second = results.Skip(1).First();
Would result in 3 calls to the database:
If the caller wishes to make multiple calls to this interface, it is recommended that they realize the results into an IEnumerable instance, for example:
var results = this.persistenceService.Query(o => o.StatusConceptKey == StatusKeys.Active, AuthenticationContext.Current.Principal).ToList();
var count = results.Count();
var first = results.First();
var second = results.Skip(1).First();
Results in only one SELECT * FROM xxx method, all results are loaded into memory and then subsequent calls are made in memory.
This may seem more efficient, however imagine a result set where only the second page is required (10 results per page), we want the COUNT of all records however only actually want to load 10 records from the database, in this case we want two SQL queries executed (one for counting and another for fetching)
var results = this.persistenceService.Query(o => o.StatusConceptKey == StatusKeys.Active, AuthenticationContext.Current.Principal);
var count = results.Count();
var results = results.Skip(10).Take(10).ToList();
This code executes two SQL queries, a SELECT COUNT(*) FROM xxxx and then another SELECT * FROM ... OFFSET 10 FETCH FIRST 10 ROWS ONLY , this greatly reduces the result set. We can also determine if we want to send queries to the database with Any, which would execute a SELECT 1 WHERE EXISTS ....
Note: You can use the AsResultSet(IEnumerable) method in order to access the delay load functions from interfaces which return IEnumerable
var wouldBeEnumerable = repository.Find(o=>o.StatusConceptKey == StatusKeys.Active);
if(wouldBeEnumerable.Any()) // results in a SELECT * FROM x - which is slow
{
Console.Write("I just did a slow thing");
}
var resultSet = wouldBeEnumerable.AsResultSet();
if(resultSet.Any()) // results in SELECT EXISTS FROM
{
Console.Write("I just did a faster thing");
}