You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Trevor Pilley edited this page Mar 13, 2020
·
3 revisions
Tuple Queries
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);
Example
// 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>.