var conversationQABySubjectId =
_repoWrapper.ConversationQuestionAnswer
.FindAll()
.Where(a => a.SubjectId == subjectId)
.GroupJoin(_repoWrapper.ContactInformation.FindAll(),
c => c.ResponderContactInformationIdentifier,
ci => ci.ContactInformationIdentifier,
(c, ci) => new { c, ci })
.Select(m => new Tuple<Domain.TC_Context.ConversationQuestionAnswer,
Domain.TC_Context.ContactInformation>(m.c, m.ci));
m.ci
抛出此错误,如下所示。当我使用Join时,此方法可以正常工作。我正在使用GroupJoin,因为我想退出Join ContactInformation表。
参数2:无法从“ System.Collections.Generic.IEnumerable”转换为“ TrainingCenter.Domain.TC_Context.ContactInformation”
添加了SelectMany
和DefaultIfEmpty
,但是没有起作用。下面是代码
var conversationQABySubjectId = _repoWrapper.ConversationQuestionAnswer.FindAll()
.Where(a => a.SubjectId == subjectId)
.GroupJoin(_repoWrapper.ContactInformation.FindAll(),
c => c.ResponderContactInformationIdentifier,
ci => ci.ContactInformationIdentifier,
(c, ci) => new { c, ci })
.SelectMany(cci => cci.ci.DefaultIfEmpty(), (c, ci) => new { c, ci })
.Select(m => new Tuple<Domain.TC_Context.ConversationQuestionAnswer,
Domain.TC_Context.ContactInformation>(m.c, m.ci));
答案 0 :(得分:0)
以下是我如何解决此问题。
var conversationQABySubjectId = _repoWrapper.ConversationQuestionAnswer.FindAll()
.Where(a => a.SubjectId == subjectId)
.GroupJoin(_repoWrapper.ContactInformation.FindAll(),
c => c.ResponderContactInformationIdentifier,
ci => ci.ContactInformationIdentifier,
(c, ci) => new { c, ci })
.SelectMany(m => m.ci.DefaultIfEmpty(), (m,n) => new Tuple<Domain.TC_Context.ConversationQuestionAnswer,
Domain.TC_Context.ContactInformation>(m.c, n));