0

I'm stuck in using LinQ, I can update using 1 filter but when using multiple it ignores the other 2 and just check the first one.

Here is the code that I am using:

One where that is working:

Engagement_History eh = qdb.Engagement_History.First(a => (a.pdPPMCID.Equals(PPMCID));

Multiple Where that is not working:

Engagement_History eh = qdb.Engagement_History.First(a => ((a.pdPPMCID.Equals("1")) && (a.ehMonth.Equals("1")) && (year.Equals("2016"))));
5
  • 3
    What is your definition of is not working ? Commented Dec 7, 2016 at 15:32
  • 9
    You have just year.Equals("2016") shouldn't this be a.year.Equals("2016") (or something)? Is this a typo in your question or is this your actual code? Commented Dec 7, 2016 at 15:32
  • What exactly is a and shouldn't you use a String.Compare rather than a Equal? Commented Dec 7, 2016 at 15:34
  • Does this statement work for you: Engagement_History eh = qdb.Engagement_History.Where(a => ((a.pdPPMCID.Equals("1")) && (a.ehMonth.Equals("1")) && (a.year.Equals("2016")))).FirstOrDefault(); Commented Dec 7, 2016 at 15:37
  • Yeah it turns out I forgot the a in year. Thanks @ChrisF. Been Coding for 7 hours straight starting to loose my mind Commented Dec 7, 2016 at 15:39

1 Answer 1

3

In your query you have just

year.Equals("2016")

as your final clause.

This should be:

a.year.Equals("2016")

Otherwise it's going to be looking for a local variable called year to compare "2016" against. If that local variable doesn't exist then you should be seeing a compiler error. If it does exist then the query will only return results if it's set to "2016".

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.