Inner Join problems on Dapper

Asked

Viewed 337 times

0

I have the following problem, when I make a Inner Join in 3 tables the Dapper does not bring me all the columns of the 3 tables but only the one of my father table Inner Join ( or is the first table in the query ).

My classes

public class ItemQuestion
{
    public int Id { get; set; }    
    public int Questao_Id { get; set; }    
    public int Resposta_Id { get; set; }    
}    

public class Question
{
    public int Id { get; set; }    
    public string Questao { get; set; }    
}  

public class Answer
{
    public int Id { get; set; }    
    public string Resposta { get; set; }

}

using(var conn = new SqlConnection(strConn))
{
    conn.Open();
    Dictionary<string, string> quest = new Dictionary<string, string>();
    return conn
        .Query<ItemQuestion, Question, Answer, ItemQuestion>
            (@"SELECT ITQ.*, Q.*, AWS.* FROM ITEM_QUESTION AS ITQ 
                INNER JOIN QUESTION AS Q ON Q.Id = ITQ.Questao_Id 
                INNER JOIN ANSWER AS AWS ON AWS.Id = ITQ.Resposta_Id",
                (itq, q, a) =>
                {
                    itq.Questao_Id = q.Id;
                    itq.Resposta_Id = a.Id;
                    return itq;

            }).ToList();                         
}
  • 4

    Possible duplicate of Multiple INNER JOINS with DAPPER

  • Another example: http://dapper-tutorial.net/result-multi-mapping

  • What is the cardinality of the three tables?

  • @pussycat QUESTION is of 1:1 to the table ITEM_QUESTION, so with the table ANSWER, already a table ITEM_QUESTION is of n:n.

  • @William a question has only one item and one answer can have several item?

  • @cat Not an item may have several answers and several questions.

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.