I've two POCO-s. A and B.
public class A{
[Slapper.AutoMapper.Id]
public int Id { get; set; }
public B BType { get; set; }
// Rest of the fields
}
public class B{
[Slapper.AutoMapper.Id]
public int Id { get; set; }
public string Name {get;set;}
}
T-SQL Stored Procedure result:
ID B_Id B_Name 1 1 B1 2 2 B2
My code to get List with Dapper is:
List<A> aList = new List<A>();
using (IDbConnection connection = new SqlConnection(GlobalConfig.ConnectionString()))
{
var p = new DynamicParameters();
p.Add("@Id", someId);
// Here debug shows me 2 correct objects inside of var list
var list = connection.Query<dynamic>("[spApp_getBlaBlaByID]", p, commandType: CommandType.StoredProcedure);
// After casting I got only 1
aList =(Slapper.AutoMapper.MapDynamic<A>(list) as IEnumerable<A>).ToList();
}
return aList; // Debugging shows only 1 one of the objects
So, what is wrong with my code? Please help to find mistake. P.S. I came to C# from Java. Maybe in C# world Slapper.Automapper is not in trend anymore. What is flexible and modern solution to map POCO-s with DAPPER?