Outer Join statement in LINQ -
i trying create outer join statement in linq , not having luck. know performing outer join requires 2 steps:
(1) convert join group join into
(2) use defaultifempty() on group generate null value expect if joined result set empty.
i have been using code example:
var query = (from p in dc.gettable<person>() join pa in dc.gettable<personaddress>() on p.id equals pa.personid tempaddresses addresses in tempaddresses.defaultifempty() select new { p.firstname, p.lastname, addresses.state }); so tried this:
var outerjoin = h in resulthours join u in results on h.key equals u.key outer dictionary in outer.defaultifempty() select new { the problem intellisense doesn't recognize in select new {} statement. i've tried u. , h., dictionary.
the problem may running i'm trying outer join 2 dictionaries. doesn't seem that, although told need do. doing wrong or not understanding something.
i need join dictionary results.unit dictionary resulthours.hours because output missing unitid fields under conditions. doing outer join supposed clear up.
here code results:
var results = (from v in vdimunit join vf in vfactenergyallocation on v.unitkey equals vf.unitkey join vd in vdimgadsevent on vf.gadseventkey equals vd.gadseventkey join vt in vdimtime on vf.timekey equals vt.timekey typecodes.contains(vd.gadseventtypecode) && vt.yearnum >= (year - 3) && vt.yearnum <= year group vf new {v.plantid, v.physicalunitid, v.netdependablecapacity, v.netmaximumcapacity, vt.monthnum} groupitem select new {groupitem.key.plantid, groupitem.key.physicalunitid, groupitem.key.netmaximumcapacity, groupitem.key.monthnum, po_hrs = groupitem.sum( x=> (float)x.allocatedenergymwh / groupitem.key.netdependablecapacity), uo_hrs = groupitem.sum(x=> (float)x.allocatedenergymwh / groupitem.key.netdependablecapacity), unit = groupitem.count(), groupitem.key}).todictionary(x=> x.key, x=> x); here code resulthours:
var resulthours = (from vt in vdimtime join vf in vfactenergyallocation on vt.timekey equals vf.timekey join vd in vdimgadsevent on vf.gadseventkey equals vd.gadseventkey join v in vdimunit on vf.unitkey equals v.unitkey group vt new {v.plantid, v.physicalunitid, v.netdependablecapacity, v.netmaximumcapacity, vt.monthnum} groupitem select new {groupitem.key.plantid, groupitem.key.physicalunitid, groupitem.key.netmaximumcapacity, hours = groupitem.count(), groupitem.key}).todictionary(x=> x.key.tostring(), x=> x.hours); this presently how have output. change after figure out how outer join.
var finalresults = (from r in results orderby r.key.monthnum, r.key.plantid, r.key.physicalunitid select new {site = r.key.plantid, unit = r.key.physicalunitid, r.key.monthnum, numerator = r.value.po_hrs, denominator = resulthours[r.key.tostring()], weight = r.key.netmaximumcapacity, data_indicator = data_indicator, budgeted = budgetedplannedoutagehrs, industry_benchmark = industry_benchmark, comments = comments, executive_comments = executivecomments, fleet_exec_comments = fleetexeccomments}); i'm @ loss. linq outer join examples have found apaprently not apply when joining dictionaries.
Comments
Post a Comment