I used Dapper for a while and wonder what Contrib and Rainbow projects were about themselves. After a short review of the code, here are my thoughts on using them:
Dapper.Contrib
Contrib provides a set of extension methods on the IDbConnection interface for basic CRUD operations:
A key component of Contrib is that it provides tracking for your objects to determine if changes have been made.
For example, using the Get method with an interface as a type constraint returns a dynamically created proxy class with an internal dictionary to track property changes.
Then you can use the Update method, which will generate the SQL necessary to update only those changed properties.
The main disclaimer . To qualify for Contrib tracking, you must use the interface as a type restriction to allow the creation of a proxy class.
Dapper.Rainbow
Rainbow is an abstract class that can be used as a base class for Dapper classes to provide basic CRUD operations:
Like some commonly used methods, such as First (gets the first record in the table) and All (gets all records of the results in the table).
For all purposes and tasks, Rainbow is basically a wrapper for the most commonly used database interactions and will create boring SQL based on property names and type restrictions.
For example, using the Get operation, Rainbow will create a vanilla SQL query and return all columns, and then map these values โโto the type used as the constraint.
Similarly, insert / update methods will dynamically create the SQL needed for insert / update based on the names of the type constraint properties.
Key Disclaimer : Rainbow expects all of your tables to have a column with the identifier "Id".
Differences?
The main difference between Contrib and Rainbow (IMO), one tracks changes in your entities and the other doesn't:
- Use Contrib if you want to track changes in your objects.
- Use Rainbow if you want to use something more along the lines of the standard ADO.NET approach.
On the side of the note: I wish I had studied Rainbow before, since I created a very similar base class that I use with Dapper.
From an article and a quote by @anthonyv cited: This annoying INSERT problem, getting data into the database
Now there are 2 other APIs that you can select ( besides Rainbow ) (for CRUD) Dapper.Contrib and Dapper Extensions . I do not think it is disposable. Depending on your problem and preference, there may be an API that works best for you. I tried to enter some of the options. There is no blessed โbest wayโ to solve every problem in the world.
I suspect Sam was trying to convey in the above quote, and the related blog post: Your script may require a lot of custom mapping (use vanilla Dapper), or you may need to track entity changes (use Contrib), or you may Be common use cases (use Rainbow), or you can use a combination of them. Or do not even use Dapper. YMMV.