I’ve been using Entity Framework for sometime now. But we all know using EF for everything may not be the best option. I decided to use Dapper for certain db queries.
Dapper requires an open SqlConnection object, I didn’t want to have to manage another connection string in my web.config so I looked at options for converting an EF connection string to an ADO connection string.
After some research I came up with the following:
private SqlConnection GetSqlConnection(DbContext dbContext)
var ec = dbContext.Database.Connection;
var adoConnStr = ec.ConnectionString;
return new SqlConnection(adoConnStr);