Dapper.Rainbow VS Dapper.Contrib

Can someone explain the difference between Dapper.Rainbow and Dapper.Contrib ?

I mean when do you use SqlMapperExtensions.cs from Dapper.Contrib and when should you use Dapper.Rainbow?

+64
orm dapper dapper-rainbow
Apr 05 2018-12-12T00:
source share
3 answers

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:

  • Receive
  • Embed
  • Update
  • Delete

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:

  • Receive
  • Embed
  • Update
  • Delete

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.

+72
Oct 24
source share

This post by Adam Anderson describes the differences between several CRUD Dapper extension libraries:

  • Dapper Contrib (Automatic change tracking - only if it is dirty or not, Attributes for user mapping, No support for composite keys, No support for manual keys)
  • Dapper Rainbow (manual change tracking using Snapshotter, attributes for user mapping, without support for composite keys, without support for manual keys)
  • Dapper Extensions (no change tracking, Fluent configuration for custom mapping, composite key support, manual key specification support) also includes a predicate system for simple queries
  • Dapper SimpleCRUD (No change tracking, Attributes for custom mapping, No composite key support, Supports manual key specification), also includes filtering / paging assistants, asynchronous support, automatic generation of the POCO class (via T4)

Dapper extensions differences

+19
Oct 24 '16 at 13:27
source share

Sam describes in detail what the difference is in his position - http://samsaffron.com/archive/2012/01/16/that-annoying-insert-problem-getting-data-into-the-db-using-dapper .

In principle, its usual non-1 size is suitable for all answers and it is up to us to decide which approach to go depending on your needs:

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.

+3
May 10 '12 at 2:07 a.m.
source share



All Articles