【问题标题】:Entity Framework multi table query实体框架多表查询
【发布时间】:2011-10-07 06:47:41
【问题描述】:

我需要有关我认为是复杂的 Entity Framework 4.1 表查询的指导。

一个项目有一个相关身份的列表。然后,用户有一个可以选择的身份列表。因此,我只想返回具有在用户列表中并被选中的身份的项目。关于如何最好地解决这个问题的任何建议?提前致谢

【问题讨论】:

    标签: linq entity-framework lambda


    【解决方案1】:

    类似这样的:

    var results = db.UserIdentities
                    .Where( x => x.UserId == someUserId && x.Selected)
                    .Select( x => x.Identity.Item);     
    

    【讨论】:

    • 感谢您的快速回复。我认为这可能有效,我正在测试它。 var results = db.UserIdentities .Where( x => x.UserId == someUserId && x.Selected) .SelectMany( x => x.Identity.Item);
    • @NullReference:如果我正确理解了您的设置,您就不需要SelectMany() - UserIdentity 和 Identity 之间不存在 1:1 关系,Identity 和 Identity 之间也存在 1:1 关系吗?项目?
    • UserIdentity 和 Identity 以及 Identity 和 Item 之间存在 *:1 关系。该模型仍然不是 100% 完美,我仍在学习 EF。再次感谢您的帮助,至少它让我走上了正轨。
    猜你喜欢
    • 1970-01-01
    • 2011-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多