3
我試着做一個自然的左Linq中加入從2個表自然連接在.NET
2個表
| questions |
+-----------+
| id |
| question |
+-----------+
| answers |
+-----------+
| id |
| q_id (fk)|
| answer |
+-----------+
我試着檢索單個行對於每一個問題,但與作爲可附加的cols需要
林不知道這是否可能
ID | Question | Answer 1 | Answer 2 | An....
| view | |-----------------------------------------------+
+-----------+ | 1 | question | answer1 | answer2 | ... |
| id | | 2 | question | answer1 | answer2 | ... |
| question | | 3 | question | answer1 | answer2 | ... |
| answer1 | or | 4 | question | answer1 | answer2 | ... |
| answer2 | | 5 | question | answer1 | answer2 | ... |
| answer3 | | 6 | question | answer1 | answer2 | ... |
| answer... | | 7 | question | answer1 | answer2 | ... |
+-----------+ |-----------------------------------------------+
我的C#Linq
var joinedTable =
from questions in db.Results
join answers in db.Answers on questions.id equals answers.result_id
into answers
select new
{
questions.id,
TOTAL_ANSWERS = answers.Count(),
questions.SurveyDateCreated,
(answers.ForEach(a=> a.answer) as "Answer" + i++)
};
肯定無法實現的加入... –
[使用LINQ的Pivot數據]的可能重複(http://stackoverflow.com/questions/963491/pivot-data-using-linq) –