ISphinx QLExecutorQueryT(String, Object) Method
Executes the given SphinxQL query and returns a list of results of the given type.
Definition
Namespace: SphinxConnector.FluentApi
Assembly: SphinxConnector (in SphinxConnector.dll) Version: 6.1.0
A list of data of the given type. If the type is a built-in type like int, string, etc. only the data from the first column is returned, otherwise an instance is created per row, and a case insensitive, direct mapping between column-name and member-name is assumed.
Assembly: SphinxConnector (in SphinxConnector.dll) Version: 6.1.0
C#
IList<T> Query<T>(
string query,
Object parameters = null
)
VB
Function Query(Of T) (
query As String,
Optional parameters As Object = Nothing
) As IList(Of T)Parameters
Type Parameters
- T
- The result type.
Return Value
IListTA list of data of the given type. If the type is a built-in type like int, string, etc. only the data from the first column is returned, otherwise an instance is created per row, and a case insensitive, direct mapping between column-name and member-name is assumed.
Example
The following example shows how to execute a query with parameters:
The next example shows a query with a built-in type as a result type:
You can also project your results into a dynamic object:
C#
using (IFulltextSession fulltextSession = fulltextStore.StartSession())
{
ISphinxQLExecutor sphinxQLExecutor = fulltextSession.Advanced.CreateSphinxQLExecutor();
var parameters = new { query = "a product", categories = new[] { 23, 42 } };
var results = sphinxQLExecutor.Query<Product>("SELECT * FROM products WHERE MATCH(@query) AND categories IN @categories", parameters);
}C#
using (IFulltextSession fulltextSession = fulltextStore.StartSession())
{
ISphinxQLExecutor sphinxQLExecutor = fulltextSession.Advanced.CreateSphinxQLExecutor();
var parameters = new { descriptions = new[] {"a description", "another description"}, query = "a product" };
var snippets = sphinxQLExecutor.Query<string>("CALL SNIPPETS(@descriptions, 'products', @query)", parameters);
}C#
using (IFulltextSession fulltextSession = fulltextStore.StartSession())
{
ISphinxQLExecutor sphinxQLExecutor = fulltextSession.Advanced.CreateSphinxQLExecutor();
var parameters = new { query = "a product", categories = new[] { 23, 42 } };
var results = sphinxQLExecutor.Query<dynamic>("SELECT * FROM products WHERE MATCH(@query) AND categories IN @categories", parameters);
}Exceptions
| ArgumentException | Occurs if query is empty. |
| ArgumentNullException | Occurs if query is null. |
| FulltextException | Occurs when there is an error during the execution of the query. |