Translate LINQ Inline query to extension method
I can't seem to figure out the LINQ Join extension method... I have t开发者_运维问答he following LINQ inline query:
var cc = from z in zipcodes
join c in contactsRepo.UDF_SelectSome() on z.Zipcode equals c.Zip
What is the equivalent of this in LINQ-extension-method syntax?
Did you mean Lambda syntax?
var cc = zipcodes.Join(contactsRepo.UDF_SelectSome(),
z => z.Zipcode,
c => c.Zip,
(z, c) => c);
If you're using the join to filter, and you want just the object from one set, use the selector (last parameter) that picks that object.
var cc = contactsRepo.UDF_SelectSome().Join(
zipcodes,
c => c.Zip,
z => z.Zipcode,
(c, z) => c);
Or, if you just want to filter:
var cc = contactsRepo.UDF_SelectSome()
.Where(c => zipcodes.Any(z => c.Zip == z.ZipCode))
精彩评论