Dapper is a micro ORM library for .NET and .NET Core applications that allows you to execute SQL queries and map the results to objects. Dapper provides various methods that you can use to perform different operations on data sources. Some of the most common methods are:
- Execute: This method executes a command one or multiple times and returns the number of affected rows in the database tables. It can be used for INSERT, UPDATE, DELETE, or other statements that do not return any result set.
- Query: This method executes a query and returns an IEnumerable<T> of mapped objects. It can be used for SELECT statements that return one or more rows of data.
- QueryFirst: This method executes a query and returns the first result as an object. It can be used for SELECT statements that return a single row of data or when you only need the first row of a result set.
- QueryFirstOrDefault: This method executes a query and returns the first result as an object or a default value if no result is found. It can be used for SELECT statements that may return zero or one row of data.
- QuerySingle: This method executes a query and returns the single result as an object. It throws an exception if no result or more than one result is found. It can be used for SELECT statements that are expected to return exactly one row of data.
- QuerySingleOrDefault: This method executes a query and returns the single result as an object or a default value if no result is found. It throws an exception if more than one result is found. It can be used for SELECT statements that may return zero or one row of data.
- QueryMultiple: This method executes a query and returns a GridReader object that can access multiple result sets by using methods such as Read<T> and ReadAsync<T>. It can be used for stored procedures or queries that return more than one result set.