Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
iam using entity framwork i need to get a user friends the diagram are in the picture

this is the diagram of the tables
Int64 userID =1;

ctx.Users.Where(x => x.FriendShips.All(y => y.Accepted == true && y.CreatorID == userID)).ToList();
Posted
Comments
Prutal 19-Dec-13 12:32pm    
the result of the above query is not what i want so how i can get all the friends of a user

1 solution

Well it might help to know what results you are expecting and what you are actually getting.

currently what you have here

y => y.Accepted == true && y.CreatorID == userID)


will only get the friendships in one direction. meaning if someone else created the friend request and your user accepted it, then they would be the 'FriendId'. If there is a row put into the Friendship table for both users then this doesn't matter, but assuming 1 friendship record for 1 relationship, you'd have to add the

y => && y.FriendId== userID)


as well.
 
Share this answer
 
Comments
Prutal 19-Dec-13 14:19pm    
lets say that i am the user and i want to get all the users that i sent them a friend request and they accept the request what will the expression be if the the above one does not get the wanted result (i cant understand the result that is retrived)
bowlturner 19-Dec-13 14:27pm    
I'm not positive (I do a lot of trial and error testing) but I don't think you need the .all in there.
Prutal 19-Dec-13 14:36pm    
so what is the answer, what will the expression be ?
bowlturner 19-Dec-13 17:36pm    
Just realized something. Most of my Lambda is using objects, so I missed this. I think you might need to use .Join to join the Friendship table to the user table using userid = createid before the where clause.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900