I have a social networking website and I’m getting some difficulties to filter who can see the updates users post.
As in Facebook, I see all posts from my friends, even if I didn’t post anything.
I have these tables:
DiaryPosts table:
--------------------------------------
| ID | UserID | Content | UpdateTime |
--------------------------------------
Friends table:
--------------------------
| ID | UserID | FriendID |
--------------------------
Followers table:
----------------------------
| ID | UserID | FollowerID |
----------------------------
And I have this query that now it can’t filter anything:
var diaryPosts = (from d in db.DiaryPosts
orderby d.ID descending
select new DiaryPostsSet
{
PostID = d.ID,
Author = db.User.Where(m => m.ID == d.UserID).FirstOrDefault().Nickname,
Thumbnail = db.User.Where(m => m.ID == d.UserID).FirstOrDefault().Thumbnail,
AuthorComment = d.Content,
UserID = d.UserID,
Time = d.UpdateTime }).Take(6).ToList();
I tried to write a where clause but it didn’t work.
Do you have any suggestions on how to write this query?
The answer is: