Alex
Alex

Reputation: 77329

Translate LINQ Inline query to extension method

I can't seem to figure out the LINQ Join extension method... I have the 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?

Upvotes: 0

Views: 2653

Answers (2)

Justin Niessner
Justin Niessner

Reputation: 245399

Did you mean Lambda syntax?

var cc = zipcodes.Join(contactsRepo.UDF_SelectSome(),
                       z => z.Zipcode,
                       c => c.Zip,
                       (z, c) => c);

Upvotes: 5

Amy B
Amy B

Reputation: 110091

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))

Upvotes: 0

Related Questions