I'm transitioning from .NET Framework to Core and, while it's been a mostly seamless and beneficial process, there are some difficulties.
The latest is how to perform the fairly simple EF-based task of taking results from a raw query and mapping those results into a list of objects of a given type. In Framework, I could so something like:
using (DbContext Context = new DbContext(Connection))
{
return Context.Database.SqlQuery<T>(Sql).ToList<T>();
}
Where Connection
would be a raw connection string, Sql
a raw query string, and T
any given type known to fit the output of the Sql.
In Core, I can't seem to grab a new Context with nothing but a connection string, and nor can I apply the SqlQuery
method. There's got to be as quick & easy a way to do this in Core, but I can't seem to find it.
I do have System.Data.Common
and System.Data.SqlClient
, along with EntityFrameworkCore
installed into the project.