Get started with your first NPoco query
masterTo perform a basic query in NPoco, define a POCO (Plain Old CLR Object) class where the property names match the database column names. NPoco performs case-insensitive mapping between column names and properties automatically, so no explicit mapping configuration is required for simple query scenarios.
- Define your model class.
- Instantiate an
IDatabaseusing a connection string name. - Use the
.Fetch<T>()method with your SQL string.
public class User
{
public int UserId { get;set; }
public string Email { get;set; }
}
// Initialize the database with a connection string name from your config
IDatabase db = new Database("connStringName");
// Execute a query and map results to the User class
List<User> users = db.Fetch<User>("select userId, email from users");