This repository was archived by the owner on Dec 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Query Tuple(s)
Trevor Pilley edited this page Mar 13, 2020
·
3 revisions
MicroLite supports returning tuples (in the .NET 4.0+ builds), this allows you to specify Tuple<T>
as the return type and retrieve an Tuple<T>
which has items matching the columns specified in the SqlQuery
.
The Tuple
type can be used with the following methods:
ISession.Include.Many<Tuple<T>>();
ISession.Include.Single<Tuple<T>>(SqlQuery);
ISession.FetchAsync<Tuple<T>>();
ISession.PagedAsync<Tuple<T>>();
ISession.SingleAsync<Tuple<T>>(SqlQuery);
// Create an ad-hoc query, this could select a number of columns across multiple tables if desired.
var query = new SqlQuery("SELECT Name, DoB FROM Customers");
// Execute the query and return the results.
var results = await session.FetchAsync<Tuple<string, DateTime>>(query);
foreach (var tuple in results)
{
// The Item properties in each tuple will contain the values
// of the column(s) specified in the query.
Console.WriteLine(tuple.Item1);
Console.WriteLine(tuple.Item2);
}
This is supported in MicroLite 5.2 onwards and supports Tuple<T1>
through to Tuple<T1, T2, T3, T4, T5, T6, T7>
.