c# - Linq and var keyword -
how can fix situation this? want use global 'var latesttests', can use object or something? general linqstatement, if need more complicated situations well.
var latesttests = ???? if(all == "") { latesttests = db.patientchecklists.where(x => x.patientmedicine.patient.clinicid == clinicid).orderby(x => x.nexttest).take(10); } else { latesttests = db.patientchecklists.where(x => x.patientmedicine.patient.clinicid == clinicid).orderby(x => x.nexttest); }
you have redundant code there. how this:
var latesttests = db.patientchecklists .where(x => x.patientmedicine.patient.clinicid == clinicid) .orderby(x => x.nexttest); if(all == "") { latesttests = latesttests.take(10); }
edit: in more complicate situations, wouldn't initialise var latesttests
in outer scope. either not using var
, or moving whole thing in separate method.
Comments
Post a Comment