Contributors: 1 Friday, November 6, 2015
Licensed under: CC-BY-SA
Not affiliated with Stack Overflow
Rip Tutorial:
Roadmap: roadmap

Using Dapper in LINQPad


LINQPad is great for testing database queries and includes NuGet integration. To use Dapper in LINQPad press F4 to open the Query Properties and then select Add NuGet. Search for dapper dot net and select Add To Query. You will also want to click Add namespaces and highlight Dapper to include the Extension Methods in your LINQPad query.

Once Dapper is enabled you can change the Language drop down to C# Program, map query results to C# classes, and use the .Dump() method to inspect the results:

void Main()
	using (IDbConnection db = new SqlConnection("Server=myServer;Trusted_Connection=true")){
		var scalar = db.Query<string>("SELECT GETDATE()").SingleOrDefault();
		scalar.Dump("This is a string scalar result:");
		var results = db.Query<myobject>(@"
		VALUES (1,'one'),
		) AS mytable(id,name)");
		results.Dump("This is a table mapped to a class:");

// Define other methods and classes here
class myobject {
	public int id { get; set; }
	public string name { get; set; }

The results when executing the program would look like this:

LINQPad screenshot