How to use Dapper in ServiceStack

◇◆丶佛笑我妖孽 提交于 2019-12-04 03:07:28

Dapper works like OrmLite in that they're both extension methods over the underlying ADO.NET System.Data.* IDbConnection interface. This means you can use both of them together on the IDbConnection retrieved from OrmLite's IDbConnectionFactory.

OrmLite includes a recent version of Dapper in ServiceStack.OrmLite under the ServiceStack.OrmLite.Dapper namespace.


In v3.9.40 of ServiceStack, this embedded version of Dapper had their APIs changed to include a 'Dapper' suffix to avoid clashing with OrmLite methods of the same name. You don't have to register a Request-Scoped IDbConnection as ServiceStack's default Service class already retrieves it from the IDbConnectionFactory for you.

Given that, here's how you can access Dapper ORM APIs inside a ServiceStack service:

public class MyService : Service
{
    public object Any(Request request)
    {
        base.Db.QueryDapper(...);
        base.Db.QueryMultipleDapper(...);
        base.Db.MultiMapDapper(...);
        base.Db.ExecuteDapper(...);
    }
}
Ram Argid

I don't know about others, but due to the information regarding Dapper within the Razor namespace this answer confused me quite a bit.

In case others have a similar experience, I've attempted to answer this same question in a basic way.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!