【问题标题】:How to select across a relationship using LINQPad?如何使用 LINQPad 在关系中进行选择?
【发布时间】:2009-05-20 13:11:15
【问题描述】:

我有一个简单的表结构

Images(image_id, image_library_id,...)

Links(link_id, image_id, link_component_code...)

我正在尝试使用 LINQ 执行一个简单的查询

var q = from i in Images where i.Link.link_component_code = "x" select i;

但是 LINQPad 中的智能感知不提供“链接”对象

where i.Link.link_component_code

相反,我只得到一个“Links”对象,它是一个 EntitySet,并没有继续列出表字段,只列出 Add、Select、Where 等方法

如果我反其道而行之

var q = from l in Links where l.Image.image_library_id = 1234 select l;

按预期工作

这个 EntitySet 是什么,我哪里出错了?

【问题讨论】:

    标签: c# linq-to-sql linqpad


    【解决方案1】:

    建立关系的方式,每张图片有 0 个或多个链接(许多链接)。 Image 的 Links 属性是相关链接记录的可查询集合。

    试试这个 where 子句

    where i.Links.Any(link => link.link_component_code == "x")
    

    【讨论】:

      【解决方案2】:

      每张图片是否有多个链接?如果不是,请将 Links 表中的 image_id 字段限制为唯一。那么你应该得到你期望的结果。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-10-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多