Skip to content
blackholeearth edited this page Jan 11, 2023 · 53 revisions

Welcome to the NPoco wiki! NPoco is a fork of PetaPoco with a handful of extra features.

Getting Started: Your first query

public class User 
{
    public int UserId { get;set; }
    public string Email { get;set; }
}

using (IDatabase db = new Database("connStringName")) 
{
    List<User> users = db.Fetch<User>("select userId, email from users");
}

alternatively, you can call without the "using" statement:

List<User> users = db.Fetch<User>("select userId, email from users");

Note: Database does auto close. so if you don't explicitly call OpenSharedConnection() , this usage is valid.

Note: Database needs to be disposed to close the connection (think of it as your connection object).

This works by mapping the column names to the property names on the User object. This is a case-insensitive match.
There is no mapping setup needed for this (query only) scenario.

Available on NuGet: Nuget
Also checkout the JabbR room if you have a question. Here are the release notes.

Standard Features

  1. Mapping
  2. Query Single Object
  3. Create Read Update Delete
  4. Query List
  5. Paging
  6. SQL Transaction Support

Extras

  1. Query onto an existing object
  2. One-to-Many query helpers
  3. Mapping to Nested Objects query helpers
  4. Dictionary<string, object> and object[] queries for dynamic results
  5. Change tracking for updates
  6. Composite Primary Key support
  7. Queries that returns Multiple Result Sets
  8. Fluent Mappings including Conventional based mappings
  9. Simple LINQ Queries v2+
  10. Query Provider
  11. Version column support
  12. IDatabase interface
  13. Sql Templating
  14. Debugging/Profiling (MiniProfiler/Glimpse)

Each of these features will be explained in their own page.