gpt4 book ai didi

c# - 关于 Linq 查询中的 ArrayIndex

转载 作者:行者123 更新时间:2023-11-30 21:09:04 25 4
gpt4 key购买 nike

当我尝试执行以下操作时,我有 LINQ 表达式节点类型 ArrayIndex is not suported in LINQ to Entities 错误

public List<AttachmentList> ShowAttachments(int type, int ReferenceId)
{

try
{
var attachmentNames =
(from attachment in tent.Attachments
where (attachment.Attachment_Type == type
&& attachment.Attachment_Reference_Pk == ReferenceId)
select new AttachmentList
{
Attachment_Pk = attachment.Attachment_Pk,
Attachment_File_Path = attachment
.Attachment_File_Path.Split(new[] {'$'})[1]
}).ToList();

return attachmentNames;
}
catch (Exception ex)
{
ExceptionHandler.ExceptionLog(ex);
return null;
}
}

如您所见,我正在尝试拆分包含 '$'Attachmentfilepath 并将第二个值 ([1]) 分配给 Attachment_FilePath

任何人都可以建议我如何拆分并将值分配给同一查询中的 AttachmentList 字符串谢谢

最佳答案

老实说,最简单的方法是在客户端进行拆分,除非您真的需要它成为一个成熟的实体。例如:

var query = from attachment in tent.Attachments
where attachment.Attachment_Type == type &&
attachment.Attachment_Reference_Pk == ReferenceId
select new { Attachment_Pk, Attachment_File_Path };

// Force the rest to execute client-side.
var attachmentNames = query.AsEnumerable()
.Select(x => new AttachmentList {
Attachment_Pk = x.Attachment_Pk,
Attachment_File_Path = x.Attachment_File_Path
.Split('$')[1]
})
.ToList();

关于c# - 关于 Linq 查询中的 ArrayIndex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9261869/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com