What’s the difference between the following two? The first 1 works but the 2nd one errors out stating that ‘Select’ cannot be found. I can’t understand why.
1st:
Office Office =
cHelper.Offices
.Where(o => o.IP3rdOctet == OSHelper.Get3rdOctetOfMyIP())
.FirstOrDefault();
2nd:
Office Office =
from o in cHelper.Offices
.Where(o => o.IP3rdOctet == OSHelper.Get3rdOctetOfMyIP())
.FirstOrDefault()
select o;
This is not an
IEnumerableorIQueryable, it is an instance ofOffice:You cannot call
selecton that. Remove the call toFirstOrDefault(), then you will be able to select the results (which will be empty if no items match your criteria).If you then still need the
FirstOrDefaultitem, then put the query in brackets and appendFirstOrDefault()like this: