2

Is:

var records = context.Records
                     .Where(r => r.EmployeeId == id)
                     .Where(r => r.Date >= startDate)
                     .Where(r => r.Date <= enddate)
                     .ToList();

Better, worse or different in anyway than:

var records = context.Records
                     .Where(r => r.EmployeeId == id
                            && r.Date >= startDate
                            && r.Date <= enddate)
                     .ToList();

The first seems easier to read, so if no difference then I would be using that to avoid using a lot of &&.

Nean Der Thal
  • 3,189
  • 3
  • 22
  • 40

1 Answers1

1
var records = context.Records
                     .Where(r => r.EmployeeId == id
                            && r.Date >= startDate
                            && r.Date <= enddate)
                     .ToList();

is Better. Less code & save time. and Both out the same result. It is just a matter of coding style.

Dhaval Asodariya
  • 558
  • 5
  • 19
  • Additionally, the single where statement with all conditions is better because you are only iterating the collection once. The multiple where statements iterate the collection multiple times... Which is slower and uses more processing to do the same work. – tpayne84 Mar 18 '21 at 20:52