c# - Populating SelectList based on three different tables -


i'm not experienced asp.net mvc nor entitity framework.

the problem following: have database table tax code sets, organizations , table 'displaydata' contains information sets linked organization. returning organizations , tax code sets works well. should able build list of tax codes based on chosen organization.

relevant code far looks this:

       ienumerable<taxcodes> taxcodelist = null;        ienumerable<organizations> orglist = null;        ienumerable<displaydata> taxcodeids = null;         model.orgid = convert.toint64(request.querystring["orgid"]);        if (model.orgid == 0)             model.orgid = 1;          taxcodelist = db.taxcodes.asnotracking().distinct().orderby(s => s.id).tolist();        orglist = db.organizations.asnotracking().distinct().orderby(s => s.org_id).tolist();        taxcodeids = db.displaydata.where(s=>s.companyid == model.orgid).tolist();         model.taxcodelist = new selectlist(taxcodelist, "id", "name");        model.orglist = new selectlist(orglist, "org_id", "org_name"); 

well, works, problem how make taxcodelist include options match organization?

thanks in advance!

try this

   taxcodeids = db.displaydata.where(s=>s.companyid == model.orgid).tolist();    taxcodelist = db.taxcodes.asnotracking().distinct().where(x=> taxcodeids.contains(y => y.id == x.tax_code_id)).orderby(s => s.id).tolist();    orglist = db.organizations.asnotracking().distinct().orderby(s => s.org_id).tolist();      model.taxcodelist = new selectlist(taxcodelist, "id", "name");    model.orglist = new selectlist(orglist, "org_id", "org_name"); 

there cleaner ways of doing it, work on now

from dd in db.displaydata join tc in db.taxcodes on dd.tax_code_id equals tc.id dd.companyid == model.orgid select tc 

that should it, bear in mind haven't tested yet tho


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -