gpt4 book ai didi

c# - LINQ to Entities 无法识别方法 'System.String get_Item(Int32)' 方法,并且无法将此方法翻译成存储表达式

转载 作者:太空宇宙 更新时间:2023-11-03 21:09:03 25 4
gpt4 key购买 nike

当我执行这个查询时,我得到这个错误:

return (from i in _ctx.TestPackages
where i.Id==TestPackageId

select new ViewTestPackageState
{
Id = i.Id,
PackageNumber = i.PackageNumber,
ReInstatement = ReturnTestPackageState(i.Id, "Reinstatment")[0],
ReInstatementReportNumber = ReturnTestPackageState(i.Id, "Reinstatment")[1],
ReInstatementSubmitDateTime = ReturnTestPackageState(i.Id, "Reinstatment")[2],

TestReportNumber = ReturnTestPackageState(i.Id, "Test")[1],
TestState = ReturnTestPackageState(i.Id, "Test")[0],
TestSubmitDateTime = ReturnTestPackageState(i.Id, "Test")[2],

CleanReportNumber = ReturnTestPackageState(i.Id, "Clean")[1],
CleanSubmitDateTime = ReturnTestPackageState(i.Id, "Clean")[2],
CleaningState = ReturnTestPackageState(i.Id, "Clean")[0],

Drying = ReturnTestPackageState(i.Id, "Drying")[0],
DryingReportNumber = ReturnTestPackageState(i.Id, "Drying")[1],
DryingSubmitDateTime = ReturnTestPackageState(i.Id, "Drying")[2],

Flushing = ReturnTestPackageState(i.Id, "Flushing")[0],
FlushingReportNumber = ReturnTestPackageState(i.Id, "Flushing")[1],
FlushingSubmitDateTime = ReturnTestPackageState(i.Id, "Flushing")[2],

LineCheckReportNumber = ReturnTestPackageState(i.Id, "LineCheck")[1],
LineCheckState = ReturnTestPackageState(i.Id, "LineCheck")[0],
LineCheckSubmitDateTime = ReturnTestPackageState(i.Id, "LineCheck")[2],

Size = i.Size.ToString(),
TestPackageOrder = i.TestPackageOrder,

}).ToList();

错误:LINQ to Entities 无法识别 'System.String get_Item(Int32)' 方法,并且此方法无法转换为存储表达式

我知道问题出在查询上,查询应该在 select 语句之前执行,所以我的问题是如何在 select 之前执行这个查询?

最佳答案

执行查询,然后从结果中选择对象

var result = (from i in _ctx.TestPackages
where i.Id==TestPackageId).ToList();

return(result.Select( new ViewTestPackageState{...}));

关于c# - LINQ to Entities 无法识别方法 'System.String get_Item(Int32)' 方法,并且无法将此方法翻译成存储表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38921950/

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