实体框架中的lambda表达式 [英] lambda expression in entity framwork

查看:78
本文介绍了实体框架中的lambda表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用实体框架我需要得到一个用户朋友图中的图片



这是表格的图表

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();

推荐答案

这可能有助于了解您期望的结果以及您实际获得的结果。



目前你在这里有什么



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)





只会在一个方向上获得友谊。意思是如果其他人创建了朋友请求并且您的用户接受了它,那么他们将成为'FriendId'。如果两个用户的友谊表中都有一行,那么这并不重要,但假设1个关系的1个友情记录,则必须添加





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.


这篇关于实体框架中的lambda表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆