Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Linq join where子句不起作用_C#_Sql Server_Linq_Join_Where - Fatal编程技术网

C# Linq join where子句不起作用

C# Linq join where子句不起作用,c#,sql-server,linq,join,where,C#,Sql Server,Linq,Join,Where,我有这个mssql查询,我想转换成linq select * from personas left join PersonaDocumento on PersonaDocumento.PersonaId=personas.Id where personas.FirstName='23895389' or PersonaDocumento.Documento='23895389' 这不起作用: from p in db.personas join d in db.PersonaDocumento

我有这个mssql查询,我想转换成linq

select * from personas
left join PersonaDocumento on PersonaDocumento.PersonaId=personas.Id
where personas.FirstName='23895389' or PersonaDocumento.Documento='23895389'
这不起作用:

from p in db.personas
join d in db.PersonaDocumento on p.Id equals d.PersonaId into dj1
where p.FirstName=='23895389' || dj1.Documento=='23895389'
from d in dj1.DefaultIfEmpty()
select p

我认为你犯了三个错误:

from p in db.personas
join d in db.PersonaDocumento on p.Id equals d.PersonaId into dj1
where p.FirstName=='Jzuan' 
from d in dj1.DefaultIfEmpty()
where d.Documento=='23895389' 
select d 
首先是在正确语法所在的位置加入d。其次,您从p中选择,而不是从您加入的表中选择,该表是d。 加上dj1是一个元素列表,所以如果您需要过滤其中的元素,您应该在之后再进行过滤。具体地说,在dj1中的from d子句中

尝试以下内容:

from p in db.personas
join d in db.PersonaDocumento on p.Id equals d.PersonaId into dj1
from ld in dj1.DefaultIfEmpty()
where p.FirstName=='Jzuan' || (ld != null && ld.Documento=='23895389')
select p

请注意我是如何重新排序子句的。

我输入错误,但where子句dj1.Documento=='23895389'根本不起作用。很难说,请将表的定义添加到您的问题中。我认为,问题与数据库定义无关,linq不支持where子句中的任何联接字段。我编辑了我的答案。dj1是一个列表,作为将来join子句的输出,请详细说明短语不起作用。