Trying to add item to linq select statement in c# -
i have long result set in linq put in ratestest, mapping result chargeelementsnullable. issue doesnt include fee record is
var fees = (from r in _dbcontext.rates r.ratetypefk == ratetype.fee && (r.localebw & localeid) > 0 && (r.policybw & policy.bitwise) > 0 && r.rateexclude == 0 select r);
so want add fees ratestest , mapping again can use add method, dont want long winded mapping 1 record.. trying add ratestest directly instead.. no joy... tried using defaultifempty expecting left join.. fee still wasnt in there..
var ratestest = (from qi in quoteinputs join r in _dbcontext.rates on qi.ratepk equals r.ratepk join fee in fees on r.ratepk equals fee.ratepk feecontainer fee in feecontainer.defaultifempty() join c in _dbcontext.covers on r.covercalcfk equals c.coverpk covers c in covers.defaultifempty() join rt in _dbcontext.ratetypes on qi.ratetypefk equals rt.ratetypepk rt.ratable == 1 || rt.ratetypepk == ratetype.postcode || rt.ratetypepk == ratetype.fee// employersliab.contains(r.inputfk) select new chargeelementsnullable { policyfk = quote.policyfk, inputfk = r.inputfk, longrate = r.longrate, ratelabel = r.ratelabel, covername = c.covername, coverfk = r.covercalcfk, coverbw = c.bitwise, listratepk = r.listratepk, ratepk = r.ratepk, ratename = r.ratename, rate = r.rate, threshold = r.threshold, excess = r.excess, divby = r.divby, discountfirstrate = r.discountfirstrate, discountsubsequentrate = r.discountsubsequentrate, hazardrating = r.hazardrating, tablefirstcolumn = r.tablefirstcolumn, tablechildren = r.tablechildren, ratetypefk = r.ratetypefk, pageno = r.pageno, suminsured = qi.suminsured, noitems = qi.noitems, ratevalue = qi.ratevalue, triggercode = rt.triggercode, territory = territory }).tolist();
you have create model 2 properties 1 quoteinputs , fees. need select both of them. eg:
class model1 { public quoteinputs quoteinputs {get;set;} public fees fees{get;set;} }
then call use model in select clause , assign model tables directly.
now let's take code , change select :
var ratestest = (from qi in quoteinputs join r in _dbcontext.rates on qi.ratepk equals r.ratepk join fee in fees on r.ratepk equals fee.ratepk feecontainer fee in feecontainer.defaultifempty() join c in _dbcontext.covers on r.covercalcfk equals c.coverpk covers c in covers.defaultifempty() join rt in _dbcontext.ratetypes on qi.ratetypefk equals rt.ratetypepk rt.ratable == 1 || rt.ratetypepk == ratetype.postcode || rt.ratetypepk == ratetype.fee// employersliab.contains(r.inputfk) select new model1{ quoteinputs = qi, fees = fee }).tolist();
Comments
Post a Comment