Kontakt

Using Dapper ORM

Sitecore Developer
Valtech

11. April 2019

Setting up Dapper in Sitecore

In one of our projects, I encountered a situation in which every developer on the project added extra lines of code to the project to send and retrieve data to and from database. Then I realized that we should have had an ORM (Object Relational Mapper) to do that for us. I investigated the existing ORMs in the market, and came up with a list of them for .Net platform, like nHibernet, Entity Framework, Dapper, etc. However, some of them were heavy duty like Entity Framework, and didn’t fit to our solution. Therefore, I came up with a sample usage of Dapper, and got approval from the SA of the project to use it. 

The sample was so light and straightforward. It basically was contained of a class with 3 generic functions called “QueryToObject”, “QueryToList” and “ExecuteStatement”, each responsible for a type of data retrieval/execution. So the developers could send a sql statement and a list of parameters to them, and let it do the rest. 

It was fast and handy, and was a valid solution to a problem that every developer was facing. 

The following is an example of how to use Dapper: 

using (IDbConnection db = new SqlConnection(connectionString))
                         {
                                db.Execute(sqlStatement, parameters);
                                 result = true;
                          }

Kontakt

Wir freuen uns auf Ihre Nachricht! Bitte füllen Sie das Formular aus. Der zuständige Mitarbeiter unseres Büros wird sich dann mit Ihnen in Verbindung setzen.
Sollten Sie ein alternatives Format und/oder Unterstützung bei der Kommunikation benötigen, um uns Feedback zu geben, wenden Sie sich bitte an Sheree Atcheson.

Let's reinvent the future