Linq to SQL - Left Outer Join multiple conditions and show all columns -
i have perused other questions regarding linking tables in linq left joins using multiple conditions , tried thought relevant examples can't create c# linq code results need.
i have 2 tables. first productionoptions , second productionorderdetailsoptions.
this contents of productionoptions table (filtered optiontype brevity)
optiontype optionvalue order showtextbox ---------------------------------------------------------- packaging black box 8 false packaging custom folding logo 4 true packaging flannel dust bag 6 false packaging folding 2 false packaging image folding 1 false packaging navy box 9 false packaging other 13 true packaging plain folding 3 false packaging polybag 5 false packaging set box black 11 true packaging set box cream 10 true packaging set box navy 12 true packaging shrink wrap 7 false
this productionorderdetailsoptions table:
orderno detailkey optiontype optionvalue optionadditionalinfo --------------------------------------------------------------------------- 000001 1 packaging image folding 000001 1 packaging polybag null 000001 1 packaging set box black needs white lettering 000007 4 packaging custom folding logo bmw
now, show rows in productionoptions table when left-joined productionorderdetailsoptions table.
here sql equivalent of linq need:
select *
productionoptions po
left join productionorderdetailsoptions o on po.optiontype = o.optiontype
, po.optionvalue = o.optionvalue
, o.orderno = '000001'
, o.detailkey = 1
po.optiontype = 'packaging'
here results like:
ostensibly want bind linq results object gridview.
if got far thank patience...
something if have fk relation:
var items = productionoptions .where(p => p.productionorderdetailsoptions == null || p.productionorderdetailsoptions.optiontype.equals(p.optiontype)) .where(p => p.productionorderdetailsoptions == null ||p.productionorderdetailsoptions.optionvalue.equals(p.optionvalue)) .where(p => p.productionorderdetailsoptions == null ||p.productionorderdetailsoptions.orderno.equals("000001")) .where(p => p.productionorderdetailsoptions == null ||p.productionorderdetailsoptions.detailkey.equals(1)) .where(p => p.optiontype.equals("packaging")) .asenumerable(); foreach(var item in result) { //productionoptions console.writeline(item.optiontype); //productionorderdetailsoptions console.writeline(item.productionorderdetailsoptions.detailkey); }
Comments
Post a Comment