我使用了string.join但没有工作。
IQueryable<CandidateVModel> list = cRepository.Table.Where(x=> !x.CFDemand.Any(y => y.AStatusId == (int) TStatus.SWork)).Select(x => new CandidateVModel
{
...
Email = x.Email,
Tags = x.Tags,
Comments= string.Join(", ",x.CFDemand.SelectMany(y=>y.JInterview.SelectMany(z=>z.JInterviewer.SelectMany(t=>t.JInterviewerFeedback.Select(a=>a.Comments))))),
Ref= x.Ref
}).AsExpandable().Where(p);
错误:消息=&#34; LINQ to Entities无法识别方法&#39; System.String Join(System.String,System.Collections.Generic.IEnumerable`1 [System.String])&#39 ;方法,并且此方法无法转换为商店表达式。&#34;
答案 0 :(得分:0)
如果不对此进行过多挖掘,解决LINQ to Entities does not recognize the method
问题的一种方法是简化您从数据库中获取的内容,并在您的viewmodel上创建一个helper属性,如下所示:
[IgnoreDataMember]
public IEnumerable<string> CommentsFromDb
{
set
{
Comments = string.Join(", ", value);
}
}
[IgnoreDataMember]
将保持此辅助属性不被序列化。
并将您的代码snippit更新为:
...
CommentsFromDb = x.CFDemand.SelectMany(y=>y.JInterview.SelectMany(z=>z.JInterviewer.SelectMany(t=>t.JInterviewerFeedback.Select(a=>a.Comments))))