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

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -