c# - Linq - getting a value that is between a lower limit and upper limit -



c# - Linq - getting a value that is between a lower limit and upper limit -

i have list of fees (linq sql entity- if relevant) - upper fee, lower fee (both decimal values). passing in property value - 90000 , want check if property value best matches one (or first value out of many) list of fees.

the fees like...

(lower fee - upper fee)

0 - 50000 50001 - 75000 75001 - 90000 90001 - 140000 190000 - 500000

out of these values, 90000 best matched 75001 - 90000 band, want pull out feedetail entity. dont know operator use, help appreciated, code far is...

[test] public void getfeerange() { const int id = 44; var propvalue = 90000; //get specific fee entity, range of fee details... var recommendedfees = reposession.all<fee>() .where(x => x.clientsurveytypeid == id) .groupjoin(_readonlysession.all<feedetail>(), x => x.feeid, y => y.feeid, (x, y) => new { feedetail = y.defaultifempty() }) .select(x => x.feedetail) .singleordefault(); assert.isnotnull(recommendedfees); //order fees lowest fee - *the bit stuck on* var bestmatch = recommendedfees.orderby(x => x.lower) .takewhile(x => propvalue >= x.lower || propvalue <= x.upper) .firstordefault(); }

question- how perform range checks? operator of linq need? not sure if should perform takewhile then, best fee range?

note: fees be...

(lower fee - upper fee)

0 - 50000 50001 - 75000 95001 - 140000 190000 - 500000

if best match found, pull out or closest match... maybe can show list of available matches if 1 not (near enough) exact match

just simple .where should fine:

var bestmatch = recommendedfees .where(x => propvalue >= x.lower && propvalue <= x.upper) .orderby(x => x.lower) .firstordefault();

c# linq

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -