gpt4 book ai didi

c# - 在 IQueryable 结果中获取索引

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

我有一个 LINQ 查询:

 var result = (from CC in hc.ClaimCodings
join CM in hc.ClaimCodingProcedureCodeModifierXrefs on CC.ClaimCodingID equals CM.ClaimCodingID
join PCM in hc.ProcedureCodeModifiers on CM.ProcedureCodeModifierID equals PCM.ProcedureCodeModifierID
where CC.CTCustomerSubID == custSub && CC.ClaimID == claimID
select new { PCM.ModifierCode });

编辑

可以返回 0 到 4 个项目。我想将每个 Modifier 代码的值设置为一个属性:

     public string ModCode1 { get; set; }

public string ModCode2 { get; set; }

public string ModCode3 { get; set; }

public string ModCode4 { get; set; }

Modcode1 = result.ModifierCode.getindex(0).firstordefault();

ModeCode2 = second result's ModifierCode;

etc

etc

除非我完全错误地处理这个问题。我还不太擅长 LINQ :(

最佳答案

这是你的想法吗?

var result = 
(
from CC in hc.ClaimCodings
join CM in hc.ClaimCodingProcedureCodeModifierXrefs
on CC.ClaimCodingID equals CM.ClaimCodingID
join PCM in hc.ProcedureCodeModifiers
on CM.ProcedureCodeModifierID equals PCM.ProcedureCodeModifierID
where CC.CTCustomerSubID == custSub && CC.ClaimID == claimID &&
PCM.ModifierCode != null
select PCM.ModifierCode
).ToList();

ModCode1 = result.Length > 0 ? result[0] : null;
ModCode2 = result.Length > 1 ? result[1] : null;
ModCode3 = result.Length > 2 ? result[2] : null;
ModCode4 = result.Length > 3 ? result[3] : null;

主要变化:

  • 已添加 PCM.ModifierCode != null在 LINQ 查询中检查。
  • 删除了多余的匿名类型结构。
  • 将 LINQ 查询结果转换为 List<string>通过ToList() .

但是,正如 BrokenGlass 所说,您最好还是存储一个列表。

关于c# - 在 IQueryable 结果中获取索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10486976/

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