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();
}
Possible duplicate of Multiple INNER JOINS with DAPPER
– novic
Another example: http://dapper-tutorial.net/result-multi-mapping
– novic
What is the cardinality of the three tables?
– gato
@pussycat
QUESTION
is of1:1
to the tableITEM_QUESTION
, so with the tableANSWER
, already a tableITEM_QUESTION
is ofn:n
.– William
@William a question has only one
item
and one answer can have severalitem
?– gato
@cat Not an item may have several answers and several questions.
– William