Dapper: read multiple results with type array not generics

dapper

Question

I have a 3 part query that I am reading using QueryMultiple. My problem is on the first Read<T> I need to split the query into 12 different classes, which Dapper does not support from what I could see. Before I used QueryMultiple, my query was only one part and I was using the method from this example Using Dapper to map more than 5 types to get 12 different classes. My question is, how can i split the first Read<T> into twelve classes and then continue with the GridReader? Please note I cannot create one big query.

public static IEnumerable<TReturn> Query<TReturn>(this IDbConnection cnn, string sql, Type[] types, Func<object[], TReturn> map, dynamic param = null, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null);

UPDATE I tested this method I added to the Dapper file and it worked, but I was only referencing the DLL and not the actual file in my app so I am not sure how to add this on without taking in the Dapper file from github. I was hoping there was built-in support for what I wanted and I just missed it somewhere in the code. Thanks for any help.

  public IEnumerable<TReturn> Read<TReturn>(Type[] types, Func<object[], TReturn> func, string splitOn = "id", bool buffered = true)
  {
    var identity = this.identity.ForGrid(typeof(TReturn), types, gridIndex);

    try
    {
      foreach (var r in SqlMapper.MultiMapImpl<TReturn>(null, default(CommandDefinition), types, func, splitOn, reader, identity, false))
      {
        yield return r;
      }
    }
    finally
    {
      NextResult();
    }

  }

Popular Answer

As i was about to add a pull request i noticed someone was one step ahead of me. Seems this functionality is not included in Dapper right now.

https://github.com/StackExchange/dapper-dot-net/pull/308



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