简体   繁体   中英

Entity framework using statement with Dapper

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.

只需使用 Dapper 的context.Database.Connection.Query<T>() ,因为它只是DbConnection的扩展。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM