1

I am working on 3-tier Architecture project and I have multiple DropDown Lists to make filtering of data that is fetched from database using LINQ.

Now I need a way to filter with these dropdowns where when I select an item in any dropdown it is filtering and when I select from two dropdowns to filter by these two selections and so on...

I use linq like this:

var doctors = from d in db.Doctors
              where d.CityID == id
              && d.HasSecretary == hasSec
              && d.OldSystem == oldSys
              && d.MetDoctor == metDoc
              && d.PriceProblem == priceProb
              && d.EasyToConvince == easyToCon
              && d.ComputerSavvy == comSav
              && d.Sold == sold
              && d.NotInterested == notIntr
              && d.FollowUp == followUp
              && d.NewClinic == newClin
              && d.RequestedADemo == reqDemo
              select d;

And it is filtering only when I select all dropdowns, and not individually.

Please help :)

1
  • Did you end up finding a solution? Commented Jul 29, 2015 at 14:59

1 Answer 1

1

You will have to do conditional where clauses e.g.

var doctors = from d in db.Doctors;

if (id != null)
  doctors = doctors.Where(d => d.CityID == id);
if (hasSec)
  doctors = doctors.Where(d => d.HasSecretary == hasSec);

// other if statements

// results
var results = doctors.ToList();
Sign up to request clarification or add additional context in comments.

1 Comment

@IbrahimSamara no problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.