【问题标题】:How do I select multiple tables in LINQ?如何在 LINQ 中选择多个表?
【发布时间】:2012-03-05 14:43:10
【问题描述】:

在 SQL 中我有:

 SELECT gu.*, cu.*
 FROM [gene_genunit] as gu, [cont_unitati] as cu
 WHERE gu.COD_UNIT = cu.COD_UNIT

我有一个 WPF 应用程序。

【问题讨论】:

    标签: c# .net sql wpf linq


    【解决方案1】:

    LINQ 等效项是

    from gu in context.Gene
    join cu in Context.Cont
    on gu.Code_Unit equals cu.Code_Unit
    select new 
    {
       gu,
       cu
    }
    

    使用LinqPad 生成查询并学习 Linq

    【讨论】:

    • “它没有提到'FROM 子句'”是什么意思?
    • @Misi 忽略我对 From 子句的评论。看看代码就行了。
    【解决方案2】:
    ARHIEntities ARHModel = new ARHIEntities(); // ARHIEntities is the model name
    var qry = from gu in ARHModel.gene_genunit
              from cu in ARHModel.cont_unitati
              where gu.COD_UNIT == cu.COD_UNIT
              select new { cu, gu };
    

    编辑:添加了where 子句

    【讨论】:

    • 这是一个交叉连接,它与在sql中做左连接不同。
    猜你喜欢
    • 2016-04-06
    • 1970-01-01
    • 2010-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-05
    • 1970-01-01
    • 2011-04-20
    相关资源
    最近更新 更多