问题描述:

I have an application where I have a aspnet_Users table that stores my users, a FriendMapping table that holds all the user's friends (friends are defined as other users on the site), lastly I have a Posts table that holds posts that users wrote.

I am trying to make a linq query to get all the user's friend's posts:

public static IQueryable<FriendMapping>(this MyEntites context, Guid userId){

return (from friendMapping in context.FriendMapping

.Include('aspnet_Users.Posts')

select friendMapping).Where(x=>x.UserId == userId);

}

This returns all the user's friends and includes their posts. How do I make it so I can just get a list of all my friend's posts and OrderByDate. I would also like to use .Take() and .Skip() to be able to get the results in sections. Anyone have any ideas?

If i iterated through the results and compiled a list, wouldn't that query have to execute first causing unnecessary data retrieval? Maybe an approach on how I can avoid using a foreach loop after just to build the Posts list and order/filter from there

相关阅读:
Top