How to implement Unit Of Work pattern with Dapper?

This Git project is very helpful. I started from the same and did some changes as per my need. public sealed class DalSession : IDisposable { public DalSession() { _connection = new OleDbConnection(DalCommon.ConnectionString); _connection.Open(); _unitOfWork = new UnitOfWork(_connection); } IDbConnection _connection = null; UnitOfWork _unitOfWork = null; public UnitOfWork UnitOfWork { get { return _unitOfWork; … Read more

Dapper.Rainbow VS Dapper.Contrib

I’ve been using Dapper for a while now and have wondered what the Contrib and Rainbow projects were all about myself. After a bit of code review, here are my thoughts on their uses: Dapper.Contrib Contrib provides a set of extension methods on the IDbConnection interface for basic CRUD operations: Get Insert Update Delete The … Read more

Does Dapper support the like operator?

Try: term = “whateverterm”; var encodeForLike = term => term.Replace(“[“, “[[]”).Replace(“%”, “[%]”); string term = “%” + encodeForLike(term) + “%”; var data = conn.Query(@” select top 25 Term as Label, Type, ID from SearchTerms WHERE Term like @term”, new { term }); There is nothing special about like operators, you never want your params inside … Read more

Dapper.NET and stored proc with multiple result sets

QueryMultiple supports the ability to deal with multiple result sets. The only design restriction we added was totally disabling buffering for the grid reader. This means the whole API is streaming. In the simplest case you can use: var grid = connection.QueryMultiple(“select 1 select 2”); grid.Read<int>().First().IsEqualTo(1); grid.Read<int>().First().IsEqualTo(2); In the slightly more sophisticated case you can … Read more

How to create arguments for a Dapper query dynamically

Yes: var dbArgs = new DynamicParameters(); foreach(var pair in args) dbArgs.Add(pair.Key, pair.Value); Then pass dbArgs in place of args: var stuff = connection.Query<ExtractionRecord>(query, dbArgs); Alternatively, you can write your own class that implements IDynamicParameters. Note that if you are starting from an object (the usual approach with dapper), you can also use this template with … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)