LINQ "IN" Question

J

jpuopolo

All,

I have an array of objects, where each object holds an ID (int) and a
name (string).
I have a database table T, each row of which holds an ID (int) and a
name (string).

I want to write a LINQ query that pulls out all of the items in the
database that have corresponding IDs in the objects of the array. For
example, if the array's objects contain the IDs 1,2,3,4,5 and the DB
contains rows with IDs 4,5,6,7, I would want the records 4,5 from the
database.

Is there a simple LINQ-esque way to do this?

Many thanks,
jpuopolo
 
J

jpuopolo

Hi, all...

I just solved my own problem. What I describe in my post is a classic
inner join, which LINQ happily accommodates.
Here is a snippet that finds the intersection of a test list of people
and students:

var j = from p in plist
join s in slist on p.Id equals s.Id
select p.Name;


I need more sleep.

jpuopolo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top