LINQ to Entities不能识别'System方法.字符串get_Item (Int32) & # 39

本文关键字:Item get Int32 字符串 方法 不能 Entities to 识别 System LINQ | 更新日期: 2023-09-27 18:02:06

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

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之前执行这个查询?

LINQ to Entities不能识别'System方法.字符串get_Item (Int32) & # 39

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

var result = (from i in _ctx.TestPackages
   where i.Id==TestPackageId).ToList();
return(result.Select( new ViewTestPackageState{...}));
var rawList = (from i in _ctx.TestPackages where i.Id==TestPackageId).ToList();
return rawList.Select(i => new ViewTestPackageState
       {
           Id = i.Id,
           PackageNumber = i.PackageNumber,
           ReInstatement = ReturnTestPackageState(i.Id, "Reinstatment")[0],
           // etc