I’m wondering if its possible to join together IEnumerable’s.
Basically I have a bunch of users and need to get their content from the database so I can search and page through it.
I’m using LINQ to SQL, my code at the moment it:
public IEnumerable<content> allcontent;
//Get users friends
IEnumerable<relationship> friends = from f in db.relationships
where f.userId == int.Parse(userId)
select f;
IEnumerable<relationship> freindData = friends.ToList();
foreach (relationship r in freindData)
{
IEnumerable<content> content = from c in db.contents
where c.userId == r.userId
orderby c.contentDate descending
select c;
// This is where I need to merge everything together
}
I hope that make some sense!
Matt
If you know your users will have less than 2100 friends, you could send the keys from the data you already loaded back into the database easily:
What happens here is that Linq translates each Id into a parameter and then builds an IN clause to do the filtering. 2100 is the maximum number of parameters that SQL server will accept… if you have more than 2100 friends, you’ll have to break the ID list up and combine (Concat) the result lists.
Or, if you want a more literal answer to your question – Concat is a method that combines 2 IEnumerables together by creating a new IEnumerable which returns the items from the first and then the items from the second.