Difference between && and where condition in entity framework query

c# entity-framework if-statement linq performance

Question

In an entity framework query, what's the difference between and condition and two where conditions?

Code 1

In my query, I'm utilizing two where clauses.

 dbContext.Projects.Where(p=>p.ProjectId!=ProjectId).Where(p=>p.Name==Name)
 .SingleOrDefault();

code 2

Without utilizing two where conditions, I have the using && condition.

  dbContext.Projects.Where(p=>p.ProjectId!=ProjectId &&  
  p.Name==Name).SingleOrDefault();

  • What separates the numbers code1 and code2?

The both queries are return same value. but i don't know the differences. Please explain to me, which one is better. and why?

1
7
9/12/2016 11:22:14 AM

Accepted Answer

ZZZ_tmp
11
5/6/2015 7:35:35 AM

Popular Answer

According to the records

Return value:

An IEnumerable that contains elements from the input sequence that satisfy the condition.

then the secondwhere just the records following the first in the listwhere - that's the same as the && expression you created in code 2.

Look at: zzz-21 zzz



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow