Entity framework using statement with Dapper

c# dapper entity-framework linq

Question

All of my existing using statements look like the following:

using (var context = new AppContext())
{
}

Now what if I want to use Dapper to pass a sql string directly to the database rather than:

context.Database.SqlQuery(sql);

After looking at the Dapper documenation it looks like it just uses a regular connection string. I am unsure of how to adjust my using statement declaration.

I want to be able to do the following like all of the Dapper examples show:

connection.Query(sql);

I am really hoping dapper will help me with populating custom properties. For example I used a partial class to extend one of my entity framework properties. Currently when I use pass a sql query through linq this property does not get populated even though it is in the Select.

Accepted Answer

Just use context.Database.Connection.Query<T>() from Dapper since it is just an extension to DbConnection.



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why