Matching multiple classes with dapper

asp.net-mvc asp.net-mvc-3 dapper

Question

How can I retrieve this objects with Dapper? For example:

public class ClassA
{
    public int Id { get; set; }
    public string Text { get; set; }
    public ClassB b { get; set; }
    public ClassC c  { get; set; }
    public ClassD d { get; set; }
    public ClassE e { get; set; }
    public ClassF f { get; set; }
}

public class ClassB
{
   public int Id {get; set;}
   public string Text {get; set;}
}
    ...

public class ClassF
{
   public int Id {get; set;}
   public string Text {get; set;}
}  

I use connection.Query<ClassA, ClassB, ClassC, ClassD, ClassE, ClassF, ClassA>(sql, ... ) but Dapper only allows multi mapping with maximum 5 arguments.

Thanks

Popular Answer

Well, finally I move the fields that I need to de main class.

public class ClassA
{
    public int Id { get; set; }

    public string Text { get; set; }

    public string TextB { get; set; }

    public string TextC{ get; set; }

    public string TextD{ get; set; }
}



    using (var sqlConnection = new SqlConnection(connStr))
                {
                    OpenConnection(sqlConnection);
                    string sql = @"select a.id 'Id', a.text 'Text', b.text 'TextB', c.text 'TextC', d.text 'TextD' 
                                    from tableA a inner join tableB b on a.idB = b.id inner join tableC c on a.idC = c.id 
                                         inner join tableD d on a.idD = d.id";
                    var rows = sqlConnection.Query<ClassA>(sql).ToList();
                    return rows.ToList();
                }



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