“LINQ to SQL 查询无法转换”错误

本文关键字:转换 错误 查询 LINQ to SQL | 更新日期: 2023-09-27 18:34:39

下面是查询:

children = (from r in masterDB.mrrel_Limited2s
                            join s in masterDB.mrconso_SnoMed2014_LimitedToDiseaseBranches on r.AUI2 equals s.AUI                            
                            join a in masterDB.tbl_patients_problems_problemId_to_SnoMed_Iteration2_before_doc_final_s on s.SCUI equals a.SnoMedScui into aGroup
                            from aa in aGroup.DefaultIfEmpty()
                            join g in masterDB.tbl_patients_problems_to_snomed_groups_2014s on s.SCUI equals g.SnoMedScui into gGroup
                            from gg in gGroup.DefaultIfEmpty()
                            where r.AUI1.Equals(node.Value.Split(new string[] { " @ " }, StringSplitOptions.RemoveEmptyEntries)[0])
                            &&
                            r.REL.Equals("CHD")
                            select new RadTreeNode(
                                s.AUI + " @ " + s.SCUI + " @ " + aa != null && gg == null ? "1" : "0" + " @ "
                                + gg != null ? gg.GroupName : "0" + " @ " + s.SCUI,
                                s.STR
                                )).ToList();

我正在尝试连接满足几个条件的两个表(底部有两个 where 子句(,然后在另外两个表上左连接该集合。我收到"无法翻译查询"运行时错误。所有的建议都值得赞赏。提前谢谢。

“LINQ to SQL 查询无法转换”错误

造成这种情况的主要原因之一是您使用了 csharp 中在 SQL 中无效的函数。所以你的节点。Value.Split就是一个例子。在 linq 查询单独的行之外执行此操作,并将生成的数组传递到 linq 中。

var nodePart = node.Value.Split(new string[] { " @ " }, StringSplitOptions.RemoveEmptyEntries)[0]
children = (from r in masterDB.mrrel_Limited2s
                            join s in masterDB.mrconso_SnoMed2014_LimitedToDiseaseBranches on r.AUI2 equals s.AUI                            
                            join a in masterDB.tbl_patients_problems_problemId_to_SnoMed_Iteration2_before_doc_final_s on s.SCUI equals a.SnoMedScui into aGroup
                            from aa in aGroup.DefaultIfEmpty()
                            join g in masterDB.tbl_patients_problems_to_snomed_groups_2014s on s.SCUI equals g.SnoMedScui into gGroup
                            from gg in gGroup.DefaultIfEmpty()
                            where r.AUI1.Equals(nodePart)
                            &&

问题出在

s.AUI + " @ " + s.SCUI + " @ " + aa != null && gg == null ? "1" : "0" + " @ "
                                + gg != null ? gg.GroupName : "0" + " @ " + s.SCUI

改成这样:

s.AUI + " @ " + s.SCUI + " @ " + (aa != null && gg == null ? "1" : "0") + " @ "
                                + (gg != null ? gg.GroupName : "0") + " @ " + s.SCUI

它现在似乎正在工作。感谢约翰帮助我解决另一个问题