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

Query Poco

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

MicroLite supports returning unmapped pocos (read-only classes), this allows you to project query results into a custom strongly typed object which doesn't map directly to a single table (or is just a subset of the columns in a table).

Pocos 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

// Convention mapped read-only class (no identifier required)
public class CustomerSummary
{
    public string Name { get; set; }
    public int Age { get; set; }
}
var sqlQuery = new SqlQuery(
    "SELECT Name, Age FROM Customer WHERE CustomerId = @p0",
    1024);
 
var customerSummary = await session.SingleAsync<CustomerSummary>(sqlQuery);
 
Console.WriteLine(customerSummary.Name);
Console.WriteLine(customerSummary.Age);

This is supported in MicroLite 5.2 onwards.

Clone this wiki locally