【问题标题】:Entity framework and Exists clause实体框架和 Exists 子句
【发布时间】:2011-01-23 15:57:21
【问题描述】:

我是 EF 的菜鸟,所以,很抱歉我的问题可能很愚蠢。

我有 2 个没有任何关系的实体(VS 不加载联接,我无法手动添加它,因为子项的主键使用其父项的派生键)。

例子

实体主
产品
键 GKey_K、Product_K
领域.....

实体详情
通用信息
键 GKey_K、GI_K
字段 Product_K, ....

好吧,我的问题很简单(我希望我的英文也是如此!),我如何才能只阅读对 GenericInformation 有一些参考的产品?

TIA

可能重复:
Best way to check if object exists in Entity Framework?

【问题讨论】:

  • 这不是 1802286 的副本,因为它正在检索产品,而在该问题中它只是检查单个对象的存在。

标签: .net linq entity-framework


【解决方案1】:

SQL 中的EXISTS ~= LINQ 中的Any

var q = from p in Context.Products
        where Context.GenericInformation.Any(gi => gi.Product_K == p.Product_K)
        // add other columns to the where if need be; I can't tell what the 
        // relationship is supposed to be
        select p;

【讨论】:

    猜你喜欢
    • 2011-12-31
    • 2011-10-21
    • 2010-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多