如何字符串数组转换字符串值,在linq行
本文关键字:字符串 linq 转换 数组 | 更新日期: 2023-09-27 18:27:21
我使用了字符串连接,但不起作用。
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);
错误:消息="LINQ to Entities无法识别方法"System.String Join(System.String,System.Collections.Generic.IEnumerable`1[System.String])",并且此方法无法转换为存储表达式。"
在不深入研究的情况下,解决LINQ to Entities does not recognize the method
问题的一种方法是简化从数据库中获得的内容,并在视图模型上创建一个助手属性,如下所示:
[IgnoreDataMember]
public IEnumerable<string> CommentsFromDb
{
set
{
Comments = string.Join(", ", value);
}
}
[IgnoreDataMember]
将阻止此助手属性被序列化。
并更新您的代码狙击坑为:
...
CommentsFromDb = x.CFDemand.SelectMany(y=>y.JInterview.SelectMany(z=>z.JInterviewer.SelectMany(t=>t.JInterviewerFeedback.Select(a=>a.Comments))))