-
Notifications
You must be signed in to change notification settings - Fork 302
Home
Adam Schroder edited this page Dec 19, 2024
·
54 revisions
Welcome to the NPoco wiki! NPoco is a fork of PetaPoco with a handful of extra features.
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:
Here are the release notes.
- Query onto an existing object
- One-to-Many query helpers
- Mapping to Nested Objects query helpers
- Dictionary<string, object> and object[] queries for dynamic results
- Change tracking for updates
- Composite Primary Key support
- Queries that returns Multiple Result Sets
- Fluent Mappings including Conventional based mappings
- Simple LINQ Queries v2+
- Query Provider
- Version column support
- IDatabase interface
- Sql Templating
- Debugging/Profiling (MiniProfiler/Glimpse)
Each of these features will be explained in their own page.