Skip to content
This repository has been archived by the owner on Dec 29, 2020. It is now read-only.

Query Primitive(s)

Trevor Pilley edited this page Mar 13, 2020 · 3 revisions

Primitive Queries

MicroLite supports returning primitive types, this allows you to specify string, int, bool, DateTime etc as the return type and retrieve an instance of that type containing the column value specified in the SqlQuery.

Primitive types can be used with the following methods:

  • ISession.Include.Many<T>();
  • ISession.Include.Single<T>(SqlQuery);
  • ISession.FetchAsync<T>();
  • ISession.PagedAsync<T>();
  • ISession.SingleAsync<T>(SqlQuery);

Example

// Create an ad-hoc query, this could select a single column from a table.
var query = new SqlQuery("SELECT DoB FROM Customers");

// Execute the query and return the results.
var results = await session.FetchAsync<DateTime>(query);
 
foreach (var result in results)
{
    // The result will be the type
    Console.WriteLine(result);
}

This is supported in MicroLite 4.0 onwards and supports any primitive type or any type for which a Type Converter is registered.

Clone this wiki locally