LINQ syntax - ordering of criteria -
i'm trying understand linq syntax , getting stuck. i've got line gets of people postcode i'm searching for
iqueryable<int> personidswiththispostcode = _context.addresses .where(pst => pst.postcode.contains(p)) .select(b => b.personid); this line returns people in personidswiththispostcode
persons = persons.where(ps => personidswiththispostcode.contains(ps.personid)); i'd have expected along lines of this, you're looking @ container, checking against subset of values see want.
persons = persons.where(ps => ps.personid.contains(personidswiththispostcode)); so sql point-of-view i'd think of this
bucket = bucket.where(bucket.contains(listoffish)); but seems act this
bucket = bucket.where(listoffish.contains(bucket)); i've read through lots of documentation can't head around apparently simple notion. explain way of thinking appreciated.
thanks
if personid int can't use ps.personid.contains because int not collection (or string search substring).
the correct way search personid in collection personidswiththispostcode-query returns matching personids. single personid doesn't contain collection collection of personids contains single personid.
so correct, returns persons personid in other sequence:
persons = persons.where(ps => personidswiththispostcode.contains(ps.personid)); and not:
persons = persons.where(ps => ps.personid.contains(personidswiththispostcode));
Comments
Post a Comment