c# - left join linq is not working -
i have linq query
var x = (from d in detalle n in nlj.defaultifempty() join nd in nuevodetalle on new { d.ope_idsku ,d.ope_tipo } equals new {nd.ope_idsku ,nd.ope_tipo }into nlj n in nlj.defaultifempty() select new { d, n } ).tolist();
now if it
x[0].d==null return false x[0].n==null return false x[1].d==null return false x[1].n==null fails, why?
my real select not {d,n } is
select new ope_detalle_autoventa() { createdon = d.createdon, modifiedon = d.modifiedon, ope_autoventaid = d.ope_autoventaid, ope_codope = d.ope_codope, ope_detalle_autoventaid = (tiene_nuevo_primarykey) ? guid.newguid() : d.ope_detalle_autoventaid, ope_entregado = (d.ope_entregado - (n != null ? n.ope_entregado : 0)), ope_envase = d.ope_envase, ope_estado = d.ope_estado, ope_icono = d.ope_icono, ope_idsku = d.ope_idsku, ope_name = d.ope_name, ope_pedido = d.ope_pedido, ope_preciov = d.ope_preciov, ope_prestamo = d.ope_prestamo, ope_promocion = d.ope_promocion, ope_skuid = d.ope_skuid, ope_tipo = d.ope_tipo, ope_autoventaidtarget = d.ope_autoventaidtarget, ope_skuidtarget = d.ope_skuidtarget, ope_numventa = d.ope_numventa, ope_descuento = d.ope_descuento, ope_cancelado = d.ope_cancelado, ope_folio = d.ope_folio, ope_cantcanc = 0, ope_estimado = "0" }
but fails same reason x[1].n==null
fails, (that believe), believe fails @ line
ope_entregado = (d.ope_entregado - (n != null ? n.ope_entregado : 0)),
however query doesn't fail
var restaragregados = (from r in resultadoregresar group new { r.ope_entregado } new { r.ope_idsku } agrupacion select new { agrupacion.key.ope_idsku, entregadototal=(agrupacion.sum (x=> x.ope_entregado) ) } ); list<ope_detalle_autoventa> nuevodetalle = (from d in detalle join c in cargainventario on d.ope_idsku equals c.ope_idsku clj c in clj.defaultifempty() join r in restaragregados on d.ope_idsku equals r.ope_idsku rlj r in rlj.defaultifempty () (c!=null?c.ope_carga == cargausada:c==null ) && (d.ope_entregado > ((c==null ?0:c.ope_disponibles ) - (r==null?0:r.entregadototal))) && d.ope_tipo ==tipos[i] select new ope_detalle_autoventa() { modifiedon = datetime.now, ope_autoventaid = ope_autoventaid, ope_detalle_autoventaid = d.ope_detalle_autoventaid, ope_entregado = (d.ope_entregado - ((c== null ? 0 : c.ope_disponibles) - (r == null ? 0 : r.entregadototal))), ope_envase = d.ope_envase, ope_estado = d.ope_estado, ope_icono = d.ope_icono, ope_idsku = d.ope_idsku, ope_name = d.ope_name, ope_pedido = 0,//0 por que no pidio de esta carga sino de la que ya se gastó ope_preciov = d.ope_preciov, ope_prestamo = d.ope_prestamo, ope_promocion = d.ope_promocion, ope_skuid = d.ope_skuid, ope_tipo = d.ope_tipo, ope_autoventaidtarget = d.ope_autoventaidtarget, ope_skuidtarget = d.ope_skuidtarget, ope_numventa = d.ope_numventa, ope_descuento = d.ope_descuento, ope_cancelado =d.ope_cancelado , createdon =datetime.now , ope_codope =d.ope_codope , ope_folio =d.ope_folio, ope_cantcanc =0, ope_estimado="0" } ).tolist();
i rename n c , change
on new { d.ope_idsku ,d.ope_tipo } equals new {nd.ope_idsku ,nd.ope_tipo }into nlj d.ope_idsku equals nd.ope_idsku nlj
but same error.
i solved this
if (nuevodetalle.count == 0) nuevodetalle.add(detalle [0]); ope_detalle_autoventa clone = (ope_detalle_autoventa)detalle[0].clone(); clone.ope_idsku = 0; clone.ope_entregado = 0; clone.ope_tipo = 0; list<ope_detalle_autoventa> detallecargaactual = new list<ope_detalle_autoventa>(); var x = ( d in detalle join c in nuevodetalle //on new { d.ope_idsku, d.ope_tipo } equals new { c.ope_idsku, c.ope_tipo } clj on d.ope_idsku equals c.ope_idsku clj c in clj.defaultifempty (clone) select new{ d, c}).tolist();`enter code here
you can see changed clj.defaultifempty (clone)
Comments
Post a Comment