Dapper

Dapper: Why Dapper, Query and QuerySingle, Execute: Insert, Update and Delete, Parameters and Mapping to Models.

Updated

  1. Why Dapper (Journeyman): Dapper is a small library that keeps your SQL but writes the ADO.NET code around it for you - opening the connection, adding parameters, and turning rows into objects.
  2. Query and QuerySingle (Journeyman): Query<T> reads many rows into objects; QuerySingle, QuerySingleOrDefault, QueryFirst and QueryFirstOrDefault read one; ExecuteScalar<T> reads one value. Pick by how many rows you expect.
  3. Execute: Insert, Update and Delete (Journeyman): Execute runs INSERT, UPDATE and DELETE and returns how many rows changed. To get a new row's id back, query it with QuerySingle<int>.
  4. Parameters and Mapping to Models (Journeyman): Pass parameters as an anonymous object or a model, with property names that match the @ names; lists become IN lists. Columns map to properties by name, so alias any column that doesn't match.