C# 无法将linq转换为sql查询错误
以下是查询:C# 无法将linq转换为sql查询错误,c#,sql-server,linq,linq-to-sql,C#,Sql Server,Linq,Linq To Sql,以下是查询: 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_pat
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子句,然后左连接另外两个表上的集合。我遇到无法转换查询运行时错误。谢谢你的建议。提前感谢。造成这种情况的主要原因之一是您使用了csharp中在SQL中无效的函数。因此,node.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
它现在似乎正在发挥作用。感谢John在另一个问题上帮助我你到底犯了什么错误?有几种可能的原因导致它无法将表达式\\long expression here\\转换为SQL,并且无法将其视为本地表达式。其中一个主要原因是您使用了csharp中在SQL中无效的函数。因此,node.Value.Split就是一个例子。在linq查询之外的单独行执行此操作,并将生成的数组传递到linq。未修复issue@byc:它修复了您的一个问题!