简体   繁体   中英

entity framework multi column

In sqlcommand I have this:

SELECT * 
FROM cliente c
    LEFT JOIN abono a on
        c.idcliente = a.idcliente
        and (a.estatus = 1 or a.estatus = null)
    LEFT JOIN usuario u on
        a.creadopor = u.idusuario
WHERE c.estatus = 1

We know this is not the same than this:

SELECT * 
FROM cliente c
     LEFT JOIN abono a on
         c.idcliente = a.idcliente
     LEFT JOIN usuario u on
         a.creadopor = u.idusuario
WHERE c.estatus=1
      and (a.estatus = 1 or a.estatus = null)

How can I do the first query in entity framework?

the second query in entity framework is it

from c in Conexion.conexion.conect.cliente
join a in Conexion.conexion.conect.abono
on c.idcliente equals a.idcliente into alj
from a in alj.DefaultIfEmpty()
join u in Conexion.conexion.conect.usuario
on a.creadopor equals u.idusuario into ulj
from u in ulj.DefaultIfEmpty()
where c.estatus == 1
&& (a.estatus == 1 || a.estatus == null)

but i could not get the first query

This does the trick:

from c in Conexion.conexion.conect.cliente
join a in Conexion.conexion.conect.abono.Where(x.estatus == 1 || x.estatus == null)
on c.idcliente equals a.idcliente into alj
from a in alj.DefaultIfEmpty()
join u in Conexion.conexion.conect.usuario
on a.creadopor equals u.idusuario into ulj
from u in ulj.DefaultIfEmpty()
where c.estatus == 1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM