Skip to content

Instantly share code, notes, and snippets.

@matijagrcic
Created January 12, 2015 17:47
Show Gist options
  • Select an option

  • Save matijagrcic/2fc275c12f9862e37834 to your computer and use it in GitHub Desktop.

Select an option

Save matijagrcic/2fc275c12f9862e37834 to your computer and use it in GitHub Desktop.
Glimpse with Dapper
public abstract class BaseRepository
{
internal static async Task<List<T>> Query<T>(string sql, object param = null)
{
//we use DbProviderFactories instead of SqlConnection so we can get nice results in Glimpse under SQL tab
var factory = DbProviderFactories.GetFactory(new SqlConnection());
using (var connection = factory.CreateConnection())
{
connection.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
var results = await connection.QueryAsync<T>(sql, param);
return results.ToList();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment