Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was 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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.