Dapper ORM .NET Quick Start

I have been using NHibernate for large corporate projects for a while now, but wanted to leverage a lighter ORM for some personal projects.  I did not want the overhead of configuring NHibernate and wanted something "lighter".

I have heard many developers discuss Dapper. I was interested in looking into it, but I do not like InLine SQL. I would rather use LINQ. On GitHub there is a package called SQLinq for Dapper!

The screen shots below (and ZIP file Download) shows using Dapper with Inline SQL and LINQ over a SQL Server Northwind Database. This project is a console app built in Visual Studio 2015.

If you decided to use this sample project you will need to update your connection string. (To keep this simple I am not documenting the connection method here)

1. Create a Customer Entity

2. Dapper Inline SQL Example

3. Dapper LINQ Sample

4. Console App Results

 Download DapperSample.zip C# Console App Source

SQL Server nHibernate Config

/// <summary>
/// Get Factory
/// </summary>
/// <returns></returns>
private ISessionFactory CreateSessionFactory()
       return Fluently.Configure()
             c => c.FromConnectionStringWithKey("ConnectionString")))
        .Mappings(m => m.FluentMappings.AddFromAssemblyOf<StockSymbols>())
        .Mappings(m => m.FluentMappings.AddFromAssemblyOf<StockQuotes>())

ASP.NET SQLite / NHibernate C# Demo

This is a simple / scaled down project that can be useful as an overview of NHiberate with SQLite access and to provide a project to play around with data access.
The project is setup with:
  • Boostrap
  • NHibernate
  • SQLite Database under App_Data. It also contains the backup of the original database.
  • One Customer Entity Class
  • One Customer Mapping Class
  • One Data Access Class: NHibernate Connection, Session, Selects, Saves, and Deletes
  • It also contains a script to freeze the GridView header as found on ASPSnippets.
The customer data in this app was generated by using GenerateData.com.